App - Convert some legacy Obj-C to Swift
Closed, ResolvedPublic

Description

The recently open sourced Swift language is a vast improvement over the Obj-C formerly used for iOS apps development. Among its many advantages over Obj-C, Swift is far more approachable for volunteer contributors. So if you have Obj-C / Swift skills, let's hack at Swift-ifying some app Obj-C.

Mhurd created this task.Feb 22 2017, 5:20 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptFeb 22 2017, 5:20 PM
Restricted Application added a project: Wikipedia-iOS-App-Backlog. · View Herald TranscriptFeb 22 2017, 5:22 PM
Mhurd added a subscriber: JMinor.Feb 22 2017, 5:32 PM
julbod added a subscriber: julbod.Feb 23 2017, 3:43 AM

@Mhurd I'm interested in participating to this task. Do you have any suggestions on what file/class to begin with?

Mhurd added a comment.EditedFeb 23 2017, 7:16 PM

@julbod Oh great thanks!!

I'd recommend starting with some of the simpler Obj-C "category" methods. I find it convenient to just use a "+" in the filter to see all category files:

I'd suggest...

  • a separate pull request for each conversion to ease the review process
  • if you're converting a method which doesn't already have test coverage the first commit should probably add a test file with a few tests of the method(s) being converted
  • use cool Swift things like "guard" statements, etc. The project is Swift 3 compatible!

For example, if I were converting the "NSCharacterSet+WMFExtras.m" category:

  • I'd create a branch called something like "Swift:NSCharacterSet+WMFExtras"
  • my first commit would add a "NSCharacterSet+WMFExtras.swift" test file with a few tests. These tests, written in Swift of course :) will need access to the Obj-C method(s) being tested (until conversion is complete) so you'd have to add "NSCharacterSet+WMFExtras.h" to the "Wikipedia-Bridging-Header.h" file
  • my next commit would do the conversion ensuring all tests were still passing. It would also delete the NSCharacterSet+WMFExtras.h and NSCharacterSet+WMFExtras.m files and remove the line added to the bridging header.
  • hopefully at this point the conversion is complete and the app actually still works ;)

For the moment I would avoid converting:

  • anything which is tricky to test - i.e. requires complicated mocking, visual tests, etc
  • anything in the Xcode "Legacy" group since these are scheduled to be refactored away
  • complicated objects, view controllers etc. we'll eventually want to deal with these, but there's so much low-hanging fruit to pick first
  • NSURL categories - there are bridging issues we're still trying to figure out how to best handle.

Thanks again for the interest and help!!! It's very much appreciated.

Feel free to ping me if you run into any issues or have any further questions.

Mhurd updated the task description. (Show Details)Feb 23 2017, 7:43 PM
Mhurd added a comment.Feb 23 2017, 8:21 PM

One other thing to keep in mind:

There are sometimes subtle (and not so subtle) user-facing bugs which can crop up with conversions even if unit tests pass, so expect there may be some delay and/or rounds of testing and feedback before proposed conversions are merged.

Limiting conversions to less complex category methods, as suggested in the comment above, will help, as will keeping pull requests as atomic as possible, but feel free to ask first before beginning any conversion to confirm it's a good candidate in the first place.

Mhurd renamed this task from App - Convert as much legacy Obj-C to Swift as time permits to App - Convert some legacy Obj-C to Swift.Feb 23 2017, 8:55 PM
Mhurd updated the task description. (Show Details)
MtDu added a subscriber: MtDu.EditedMar 28 2017, 1:03 AM

@Mhurd

I'll be attending the Hackathon, and am interested in learning a lot when I'm there.

This seems interesting yet not too scary for me too hop on. However, I've never written anything in Objective-C or Swift, so do you have any tips for setting up a development environment and learning the languages? (Setting up the iOS app as well, and learning how to test and use it properly when developing) Also, are there any example patches for such things described in the task? (Is this on gerrit or Phabricator)

Thanks!

Mhurd added a comment.May 18 2017, 5:34 PM

@MtDu Hi I'm sorry I missed your comment! Unfortunately I had an injury a couple months ago and wasn't sure my tendon (Achilles) would be healed enough by the time the hackathon was happening so I ended up not being able to attend :(

Regarding setting up the iOS app, the readme.md at here has instructions to get you started. For good resources for learning Swift and legacy Obj-C this site is pretty great!

Obj-C's learning curve is unfortunately a bit high (which makes having Swift all the more nice) and some of its subtleties may be tricky to navigate as a beginner, but even if converting Obj-C to Swift ends up being too tricky I'd highly recommend learning Swift and following its (open source!) evolution here. Swift's support for protocol oriented programming in particular is pretty interesting. This video lays out the concepts and this one explores the concepts further.

I hope this helps and again apologies that I can't make the hackathon! Super bummed :/

LGoto closed this task as Resolved.Mon, Feb 11, 7:50 PM
LGoto claimed this task.