Live data from Hacker News

Ask HN: If learning to develop for iOS- start with Obj C or Swift?

news.ycombinator.com

1–10 of 53 posts

Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?

#2
I can offer anecdotal evidence in favor of Swift: I attempted to learn Obj-C in the past and gave up more than once, whereas this week I downloaded the XCode 6 beta and in an hour had my first app running.

The documentation on Cocoa is still sparse, and you have to use a lot of Obj-C interfaces, so it feels like you're a level up too high; it's backwards, but better than not learning it at all.

On the other hand, if you are looking into doing it professionally, it doesn't seem possible to build complex iOS/OSX apps right now without knowledge of Objective-C.

Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?

#3
I would suggest going with Swift, but learning enough about Objective-C concepts to use the Cocoa APIs. There is a guide to interoperability between the two languages on the developer site.

For example, some sample code to call a method (here, one named 'upCommand') whenever the user swipes in the 'up' direction looks like this:

  let upSwipe = UISwipeGestureRecognizer(target: self, action: Selector("upCommand"))
  upSwipe.numberOfTouchesRequired = 1
  upSwipe.direction = UISwipeGestureRecognizerDirection.Up
  self.addGestureRecognizer(upSwipe)
A more idiomatic way in Swift to create a gesture recognizer might be to assign a closure to execute whenever the swipe is recognized.

However, because of the way Objective-C and Cocoa works, you need to define the target of the action as a string literal describing the method name, encapsulated in a 'Selector' object. This is a fundamental Objective-C feature that shows up as a common idiom in the Cocoa APIs. If you didn't know what a selector was, you might have trouble translating this API into working Swift code, since Swift has no real equivalent construct (except the 'Selector()' class described above, there only for backwards compatibility).

Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?

#4
I know you asked a closed question, but would you consider Xamarin? This way you would earn more transferable skills (C#, multi-platform toolkit, etc.) and not lock yourself in one platform. You could also develop in raw C++ and have only a thin ObjC wrapper over it.

Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?

#5
Learning, Swift for sure.

For shipping, prototyping or production work, you cannot live without some of the stuff from the community. Cocoapods, testing frameworks, AFnetworking, Reveal there's a lot. All those are obj-c and it will take some time for Swift to catch up.

Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?

#6
I don't think that it really matters that much, they are not THAT different. The harder part about learning Cocoa is learning the how to structure the application and the APIs. You might have an easier time starting with Obj-C since there will be more learning material and more sample code that you can learn from.

Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?

#7
Anecdotal evidence in favor of Objective-C (Swift wasn't around back then): at an early WWDC, a dev. who was completely unfamiliar with Objective-C finished his first Cocoa application during the "Intro to Cocoa" session, and spoke about his amazement during the feedback.

Swift is way more complicated than Objective-C, even if the syntax may seem a lot more familiar if you're used to certain other languages.

The reasons for this complexity are manifold: static type-systems of the sophistication that Swift is attempting are complex. Even if Swift were stand-alone, had an all new class-library (or non-class library as it may be), there is quite a bit of complexity there.

However, Swift is not stand-alone. It has to interoperate with the existing Objective-C class libraries. That alone would also not be a problem, had Swift's designers not chosen to go in a completely different direction from Objective-C, both syntactically and semantically. So while they did an OK job in wrapping the libraries, there just is quite a bit of fundamental mismatch that's just waiting to bite you. A small example are force-unwrapped optionals that you get out of a lot of the library calls (because nil ptrs. are OK in ObjC and Cocoa), which will blow up when you use them, without the compiler warning you! (So much for safety).

As other posters have pointed out, you will need to learn Objective-C to make sense of things.

On the other hand, Apple will push on Swift hard, and with the faddishness of the industry being what it is, you might find Swift skills in much greater demand, even if it doesn't actually make sense from an objective standpoint.

Finally, while Swift currently is completely proprietary, Objective-C actually does have non-Apple implementations and users on Linux and Windows.

Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?

#8
I learned Objective C in about a week (two days of reading, then three more days of trying stuff out).

I'm not an expert ObjC hacker, but if you already know C++ and have done a little UI work in something before then you shouldn't have much trouble.

Once I got over the hump (mostly weirdness with terminology and window manipulation), the XCode environment feels quite nice, comparable to Visual Studio with the Whole Tomato plugins.

Next up: Android. Hmmm.

Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?

#9
Learning a language is more than learning the official syntax. It's solving real problems, finding a community, looking up answers on blogs and Stack Overflow. To that end, I think the answer is definitely Obj-C, but it's not mutually exclusive. I think Swift is where C# was circa 2002 - it might be the language of the future, but back then there was still plenty of VB being written, and ditto for Obj-C.

I personally think starting with one of the WebView wrappers is a better place to start, as it gets you used to the toolchain.

Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?

#10
Pragmatic : Objective C. Swift is too "young" and unproven - there's still lot of rough edge, it's a beta. But start learning Swift in the same time. Future looking : Objective C, to be able to understand the interop still needed for Swift... but using Swift right now for most stuff.
Post reply on HN