Ask HN: If learning to develop for iOS- start with Obj C or Swift?
1–10 of 53 posts
Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?
#2The 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?
#3For 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?
#4Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?
#5For 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?
#6Re: Ask HN: If learning to develop for iOS- start with Obj C or Swift?
#7Swift 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?
#8I'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?
#9I personally think starting with one of the WebView wrappers is a better place to start, as it gets you used to the toolchain.