7 Swift 2 Enhancements iOS Devs Will Love
snydeq writes: InfoWorld's Paul Solt outlines how Apple has made good on Swift's emphasis on performance, approachability, and ease in its latest update, offering up seven worthwhile enhancements to Swift 2, along with code samples. 'Many of the enhancements to Swift, through both the Swift 2.0 update and subsequent Swift 2.1 update, have made the language more explicit and intentional, and in turns, Swift 2 code will be safer and easier to maintain for years to come (especially now that Swift is open source). New language constructs (keywords) in Swift 2 improve the readability of control flow — the order in which lines of code are executed. Thanks to these new keywords, collaborating on Swift code will be much more productive and efficient.'
Next year the headline will be "Swift 3 Introduced by Apple". Swift 3 is more intentional and safer than ever allowing iOS developers to do more, faster. Swift 3 addresses all the problems with Swift 2 and will be completely incompatible with Swift 2 and the syntax has completely changed. Swift 2 support is dropped as it is now obsolete.
In the code example, the dude's using something called "guard" like an if statement (e.g., "if argument is shit, return null now, mofos" is written as "GUARD argument is shit, return NIL now, mofos").
>> The do/while loop is now the repeat/while loop...it goes against the convention of established languages like Objective-C, JavaScript, C++, and Java.
>> The do keyword has been repurposed to create new scope, unlike every other popular language that uses it for loops.
The only rational reason I can see for these kinds of hostile changes would be to DECREASE the ability of programmers to port code between Apple and non-Apple platforms.
How far the mighty have fallen. Now we are plucking click-bait titles from the yellowest pages of the web. Did the new managment fire all human staf and program the bots to spit out random stuff that fits a particular template:
Who wants to read about [N, where N is less than 10] [insert a noun here] that [insert a reference to a group that the reader would identify with] would [love/hate/be shocked with/never new about/should have known about/must read]
Letters I and F have sharp and thus ugly corners, making the word IF ugly.
G and D on the other hand are rounded and smooth on the outside, making the word GUARD beautiful and stylish.
In the next iteration all words will have round corners and will be white.
Mit der Dummheit kämpfen Götter selbst vergebens
Woah, we have an Apple shill day today.
Why would an Apple shill care about Rust? The only impact it has on Swift is the occasional question that comes up on the swift-evolution mailing list, like "should we add this feature that Rust has?"
-jcr
The only title of honor that a tyrant can grant is "Enemy of the State."
I don't believe that apple will want swift to grow outside of the apple walled garden.
The main reason for using swift is that apple wants their developers to be locked in, on a language level. Their applications should be re-written from scratch if they want them to run on android or other plaftorms. They always went a different path to ensure this kind of lock-in. And they even found imitators, Google basically did this when they introduced java based apps.
The main reason for using swift is that apple wants their developers to be locked in, on a language level.
Oh, for crying out loud.
The reason for Swift is that Apple is highly aware of where they spend their engineering time, and Swift makes the most common Obj-C mistakes difficult or impossible to write at all. It's not some kind of Machiavellian plot.
-jcr
The only title of honor that a tyrant can grant is "Enemy of the State."
Apple have tossed out a compiler and a very rudimentary stdlib. I'm sure it ticks a box but it's not a practical language that people can use for much.
not to mention it was their developers themselves who came up with Swift and pushed for its usage...not some CEO decree.
My God can beat up your God. Just kidding...don't take offense. I know there's no God.
I don't believe that apple will want swift to grow outside of the apple walled garden.
The main reason for using swift is that apple wants their developers to be locked in, on a language level. Their applications should be re-written from scratch if they want them to run on android or other plaftorms. They always went a different path to ensure this kind of lock-in. And they even found imitators, Google basically did this when they introduced java based apps.
Right. And open-sourcing swift is just part of this nefarious plot that you've uncovered.
How, I don't know.
Do you have ESP?
Swift 3 is having a name change: it's now iSwift. Do more, faster with iSwift. Code! iSwift. It's magical, iSwift! Bring magic and buzzwords to end uers with iSwift! iSwift can do it all! Faster! Sleek! iSwift! Magical! User friendly! No more text interfaces for coding! iSwift! intelligent! iSwift secure! Do more, iSwift! Now supporting Retina! iSwift! Brushed Aluminium! Unibody iSwift!
"control flow — the order in which lines of code are executed"
Well, thanks for explaining control flow to us. Who knows, maybe there is someone here who cares about programming languages and reads news about iOS devs, and yet somehow has no clue about control flow.
Actually that would probably be a prolog programmer, come to think of it. But even then...
Swift has had source-breaking changes with nearly every version change...
What Swift ALSO has, is a migration tool built into Xcode to upgrade to new versions - so when you feel like Swift has moved into production, you run the migration tool and spend perhaps an hour or so fixing any other issues you find.
Swift has shown that languages of the past have been WAY too afraid of messing with syntax as the language changes, because it's not nearly as big a deal as it would seem.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
That defer keyword looks like the mother of all hidden bugs. If you end up finishing a statement, not in the way you intended, and all of a sudden resources are getting cleaned up before you used them. I'd stay away from that one.
I get introducing repeat to replace do, but at the same time giving do a different meaning than the rest of the languages! There will be no end to confusion over that.
Swift doesn't limit its strings to ASCII characters, and moving from one character to the next in a unicode string isn't as simple as ++.
-jcr
The only title of honor that a tyrant can grant is "Enemy of the State."
Language stability is a very big deal if you've got a sizable body of code
That's my point though; it's really not.
I'm working for a client who moved to Swift at release. At this point we have a LOT of production code in Swift, and this is all heavy database and UI code (for an enterprise app). This is not simple stuff, nor simple code...
But the language migration has caused as most a handful of hours of work over the last year or so. Much of that is because of the migration tool, without that it probably would have been more but I don't think it would have been a huge amount more. After all, we have a lot of modern tools for dealing with changing text in batch across a large codebase.
Languages forever have treated syntax as something they simply cannot change, compounding mistake after mistake of initial design because they are too afraid to break existing code. I'm here to say that fear is overblown, and more languages should not be afraid to re-work terrible syntax to make the language better.
I suppose if you're banging out the latest iOS app in six or twelve months
The app i"m on currently has been around for about five years, so no.
I've worked for many large companies with many large and very old codebases so I'm acutely aware of the need to worry about maintainable code. It's just that it turns out worries about language changes are mostly unfounded in terms of being an undue amount of work.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
Guard has the nice side effect of turning an optional into a non-optional, so that you can use a value through a whole method without having to unwrap (or worse, force unwrap) it.
without requiring the code-by-convention Disposable implementation
Frankly that sounds a lot clunkier to me than just having a nice defer block.
"repeat/while" is retarded and an unnecessary change away from well-known and accepted language conventions.
I don't know how long you've been programming but over the years I have run across times where I wanted to run through a loop at least once before checking the end condition, and had to contort a variety of things to accommodate a check at the top of the loop... I hardly think such a useful tool is retarded, when is serves so well in a specific niche.
Protocol extensions are nice, and are probably going to be quite useful in keeping your code readable. C# has had extension methods for a while now
They aren't really the same as extension methods you are talking about, because protocol extensions allow for default implementations that get overridden... both Swift and ObjC have had extensions on classes forever.
Swift protocol extensions are more like C# Abstract Classes. But you can have a class declare conformance to multiple protocols and so gain all of the methods from each, and furthermore you can in an extension on a class make any class implement a protocol and thus gain default protocol implementations...
"There is more worth loving than we have strength to love." - Brian Jay Stanley
Honestly, Slashdot, this is is the type of headline that I'd expect to see on my Facebook feed... PS. secretly hoping the use was ironic
They also have automatic migration tools to fix these things for you. In practice, it is not a problem.
I don't believe that apple will want swift to grow outside of the apple walled garden.
Yes, this is why they are porting it to Linux. Because they don't want people using it on Linux. This makes perfect sense.
Every language that is indexing into Unicode string is not handling composed characters correctly.