10 ms·
Swift, the new way to build iOS Apps. Here's how
- meoz 12y agoIt's again the same boilerplate-code to create something simple as a tableview. I don't understand why they had to 'invent' a new programming language for that.
- jameskilton 12y agoThat's not why they built Swift. Objective-C is a difficult language to work with and has decades of cruft. Swift is a start-over, but with Objective-C interop so you still have full access to the full existing APIs for OSX and iOS. Thus, the same boiler plate.
- matwood 12y agoThe thing is, understanding Obj-C was never the hard part. For example, understanding ARC, weak vs. strong (and now unowned [1]), and the various libraries is what took time and experience. Swift doesn't solve that at all and in fact offers its own oddities like the below: “You indicate type methods for classes by writing the keyword class before the method’s func keyword, and type methods for structures and enumerations by writing the keyword static before the method’s func keyword.” Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l https://itun.es/us/jEUH0.l I do think the new language is neat and will be fun to work in, but it doesn't solve the parts that tripped up many people when working in Objc. [1] @lazy var asHTML: () -> String = { [unowned self] in if let text = self.text { return "<\(self.name)>\(text)</\(self.name)>" } else { return "<\(self.name) />" } } Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l https://itun.es/us/jEUH0.l
- BugBrother 12y ago>>understanding Obj-C was never the hard part. It seems important for traction to make the beginning learning curve non-steep. See PHP, Python, etc.
- martingordon 12y agoIs there ever a time when you don't want a weak/unowned self in a block? Perhaps this should be made the default in Swift? (I understand that the Blocks spec requires all captured variables to be strong unless otherwise specified.)
- fit2rule 12y ago>>Swift is a start-over For me, Lua+LuaJIT+C/C++ as a cross-platform solution to everything is a start-over, and it gives me all kinds of things I don't get from Swift, one of them is the ability to make decisions for myself about how the basic structures of the application are going to be managed and under what conditions, either in the VM as needed or out of it, and with whatever current frameworks you want to interface with (e.g. everything). Plus, LuaJIT for the win. Plus put it, simply everywhere. (On:iOS,Linux,OSX,Win,Web,&etc.) Swift is interesting, but I will not again be swayed to the darkside of using platform-provider-provided-platforms to achieve platform nirvana, for that harness contains nails upon which to be pinned. Planks can be assembled of many kinds, but mine is shiny enough without another dastardly developer-mindset-grab by a very, very serious cult. (<<--MacbookPro'er)
- joeblau 12y agoI think the problem is with the boilerplate of objective-c. I tried to make something last night and I'll be honest, I felt like I was in Go or Scala (functional) more than I was in a C-ish style language. I'm not gonna lie, I was looking at some of the docs with a "WTF" look, but I'm a big proponent of functional programming. In the few instances that I've used it, my code has been very concise, but not always easily readable.
- rubiquity 12y agoWhat features of Swift do you find functional? What kind of functional features are you using? I'm asking out of genuine curiosity, not to put you on the spot. Thanks!
- bitpew 12y agoNot to speak for the OP, but two features bear resemblance to functional programming languages: 1) Function Types ( = higher order functions) This allows functions to be passed around as function parameters or return values. 2) Immutable variables via let let a = 1 // a is always bound to the constant 1 a = 2 // error
- emsy 12y agoI couldn't find any built in list/map/set comprehension. Did they leave it out or did I just miss it?
- deleted 12y ago[deleted]
- ktran03 12y ago“The value of a constant doesn’t need to be known at compile time, but you must assign it a value exactly once.” Excerpt From: Inc, Apple. “The Swift Programming Language.” Apple Inc. Check out this book on the iBooks Store: https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewBook?id=881256329 https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewBook?...
- chrisdevereux 12y agoYou are free to use one of the many tableview helper libraries if you aren't happy with the tradeoff between flexibility and convenience that the built-in API makes. You could argue that the frameworks should ship with such a wrapper, but I'd personally rather that they spent their time making difficult things easier than making easy things easier.
- zura 12y agoAgree. While Obj-C is one of the ugliest language, the main problem was/is API/SDK.
- orkoden 12y agoWat? Cocoa is pretty great.
- SarahJune 12y agoSo is this actually a lot easier to use than Objective-C?
- jakejake 12y agoNot sure if that was meant as sarcasm, but I'll take it as a real question..! Being a mediocre Objective C programmer myself, I really like the look of Swift. The difficulty of programming for iOS (or any platform) is partly the language syntax and partly the library/frameworks. I think Swift will help greatly with the language, but there is still a lot to learn as far as the UI kit and such. Swift doesn't really change the fundamental way the libraries work - the syntax is just cleaner (as a matter of opinion, I suppose). In addition to looking a lot more familiar and certain functions being much more readable, apparently using Swift will be safer in regards to memory issues too, which is comforting for people like me who are not guru-level with managing memory. I'm personally looking forward to using it starting this week.
- josephlord 12y agoYes...with caveats. It looks really nice, simpler syntax for the most part but the type system seems much stronger and I think those not used to functional languages/type theory may struggle to get complex things running straight away. But when it does run it should be a lot more robust (so I think it is a good change).
- gress 12y agoI think this is false. Things that are simple in Objective-C will be simpler in Swift, with better feedback from the compiler. Things that are complex in objective-c will also be simpler and more robust in swift. There is a kind of complex coding using generics and the type system that would be harder for an inexperienced developer to understand, but that seems to me to be strictly additive to Objective-C.
- josephlord 12y agoI think that Swift is better and will overall be easier (I started may comment with a "Yes") BUT there will be a fair few casts and use of optional values needed when integrating anything with the general existing libraries that would cause a beginner programmer difficulties. Example 1 - implementing a protocol (AVAudioPlayerDelagate) You get errors unless you also implement NSObjectProtocol. The easiest way to do that is to also inherit from NSObject. Example 2 - typed arrays/dictionaries You can shove any NSObject in an NSArray or NSDictionary but the Swift arrays are typed (a good thing) but one that may make some things more difficult for beginners. I suspect it is the tip of the iceberg of type related complication. This is a worthwhile tradeoff for greater safety and despite this Swift will still be easier to use overall that ObjC in my view. It may also take a while for the documentation particularly across the internet to catch up with the quantity of examples for Obj C but this is only an interim issue.
- samirmenon 12y ago"programming language called Swift which replaces Objective-C" Does Swift really replace Objective-C?
- ktran03 12y agoNot officially yet, but in due time I think it's inevitable.
- weegee101 12y agoNo, it doesn't. It is a great way to do 99% of the tasks most developers do. There is, and always will be, a place for Obj-C on the Macintosh platforms. Apple recognizes that most developers don't need the verbosity and tight-knit compatibility with C that Obj-C provides, and that is where Swift comes in.
- pjmlp 12y agoI see Objective-C been shown the door if Swift is successful, it just needs a few iOS and OS X releases, with C left around for the UNIX layer. Lets say around XCode version 10 gets released.
- weegee101 12y agoThat is extremely unlikely. Enough so that I would bet money on it. Swift is targeted at the largest user base of the Obj-C language, the iOS developers. Obj-C will be around for a long time both for legacy purposes and because Swift doesn't interop with K&R C (unless that code has an Obj-C wrapper, like CoreFoundation), and C++ code. Since both Swift and Obj-C support using Cocoa libraries, any API added to Cocoa will be usable by both, but Cocoa is only one of many libraries in the Macintosh ecosystem. Swift will become a replacement for the development the vast majority of people do, but that doesn't mean that Obj-C is going away. Apple has done nothing to indicate so; they've really been stressing the point that Swift is intended as a new tool to work along side your old one (Obj-C).
- 12y ago
- jpb0104 12y agoQuick question. Can Swift be used to build OSX applications?
- chrisdroukas 12y agoYes. https://developer.apple.com/library/prerelease/mac/referencelibrary/GettingStarted/LandingPage/index.html#//apple_ref/doc/uid/TP40014345 https://developer.apple.com/library/prerelease/mac/reference...
- jamra 12y agoIt all compiles using the same compiler so you can not only create OS X apps, but you can create hybrid Swift/Objective-c apps.
- _pmf_ 12y agoSwift is the new Visual Basic.
- sdegutis 12y agoActually it's a lot more like the new C#, which is probably a good thing.
- petilon 12y agoHow do you specify public vs private members? The language seems to be missing private/public keywords, and protocols (interfaces) are automatically generated.
- chrisdevereux 12y agoYou can't at the moment, but you will be able to soon: http://stackoverflow.com/questions/24003918/does-swift-have-access-modifiers http://stackoverflow.com/questions/24003918/does-swift-have-...
- jamra 12y agoYou can create protocols with Swift. Did you mean that protocols also suffer from the same public/private issues?
- TruthSHIFT 12y agoAre we allowed to talk about this? Isn't this still under NDA?
- myko 12y agoNo, Swift isn't under NDA This is based on a SA thread posted by a Swift team member that I linked in another HN thread, the post is available here: http://forums.somethingawful.com/showthread.php?threadid=3639638&pagenumber=1 http://forums.somethingawful.com/showthread.php?threadid=363... and the relevant quote is from the second post: Is this under NDA? No. Is this open source? Not yet. It probably will be, but I can't make promises. Right now, our repository still has a lot of history that we don't want to make public, and we have a lot of work to do before we release.
- FroshKiller 12y agoConsidering that the book is available from Apple for free on the iBooks store....
- smackfu 12y agoThe developer web pages are on public URLs that don't have any developer authentication or headers that say they are non-public information. It would be quite ironic if registered developers were under an NDA but the public was not. https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5 https://developer.apple.com/library/prerelease/ios/documenta...
- andrewdanks 12y agoI think the author misses the point of the `let` keyword. It's not meant as the equivalent of declaring constants in Objective-C; they're main purpose isn't to be global and static like constants.
- rubiquity 12y agoAnd yet you've managed to shed no light on how constants should be used in Swift.
- andrewmunsell 12y agoTo shed some light on the practice of using `let` vs. `var`, an excerpt from the book by Apple: “If a stored value in your code is not going to change, always declare it as a constant with the let keyword. Use variables only for storing values that need to be able to change.” Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l https://itun.es/us/jEUH0.l
- jquave 12y agoThanks Andrew, I am updating the posts as I learn more. We're all still learning.
- gress 12y agoLet is fine for defining constants, but it should also be used whenever possible for two reasons: 1. It gives you additional safety against accidental reassignment. 2. It gives the compiler a major optimization hint since the value is not a variable.
- Jweb_Guru 12y agoThe latter isn't really true when it comes to local variables. Compilers are pretty good at figuring that sort of thing out these days.
- 12y ago
- jquave 12y agoBTW, part 2 is here: http://jamesonquave.com/blog/developing-ios-apps-using-swift-tutorial-part-2/ http://jamesonquave.com/blog/developing-ios-apps-using-swift...
- grin 12y agoAnd the github project is here: https://github.com/jquave/Swift-Tutorial https://github.com/jquave/Swift-Tutorial
- Kidnznet 12y agoFree downloadable ebooks can be found there: http://www.iphonetransferrecovery.com/Swift/free-ebooks.html http://www.iphonetransferrecovery.com/Swift/free-ebooks.html
- desireco42 12y agoWhat's the deal with optionals? I am not sure what the use case are. Seems much better then ObjectiveC
- netcraft 12y agoThe docs seem to cover it pretty well: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-XID_428 https://developer.apple.com/library/prerelease/ios/documenta... But the basic idea around optionals is a much better and cleaner way of dealing with possible null (nil) values. Lots of other languages have and are getting optionals.
- desireco42 12y agoWhat was confusing me that they would specify it during initialization.
- Zaheer 12y agoI'm aggregating resources to learn Swift for both new/existing iOS devs. Check it out at: http://www.LearnSwift.tips http://www.LearnSwift.tips Mostly for selfish reasons to share it easily with friends.
- red40 12y agoIs the extension keyword a form of reflection?
- markcrazyhorse 12y agoThere is an awesome Swift Cheat Sheet and Quick Reference: http://swift-cheatsheet.co.uk http://swift-cheatsheet.co.uk