Swift 2 Apps in the App Store
developer.apple.com
developer.apple.com
I did have to guess around an obscure compile issue (solution: "Clean Build Folder"), but after that it was clear sailing.
My overall Swift experience has been terrific. I’m not the first to say this, but to anyone who’s wondering if it’s “ready”, yeah, it’s ready.
http://stackoverflow.com/questions/32586144/upgraded-to-swif...
I didn't know about using the Alt key to reveal "Clean Build Folder", and I've been doing iOS dev for years. I'll add this to the list of unhelpful compile errors that are fixed by cleaning the build.
Definitely a good trick to know.
alias nuke="rm -rf ~/Library/Developer/Xcode/DerivedData/"Dunno about exceptions, though. I've seen lots of great arguments against them on HN and elsewhere, and the error reference (or alternatively double-return via tuple, especially since you can name tuple slots) seemed more clear.
I've just updated the app to Swift 2 and it's all working great.
The only issue has been related to the new Bitcode feature in iOS, which isn't Swift-specific. It's been very difficult getting third-party libraries with Bitcode support, but Bitcode is required for watchOS 2 apps.
I rewrote the extension in Objective C and uploaded another build, and after a few minutes, I was able to submit it to the App Store.
Just a random anecdote that made me go back into late adopter mode for the rest of the year. It's great that Swift mostly works, but I'm really scared of the times when it doesn't.
(Edit: Not just me - https://forums.developer.apple.com/message/50182#50182)
Anyway, Swift is a great language though I don't mean to discredit it. It just doesn't take the spot of my #1 -- Scala. :)
trait Robot
var serialCode = generateSerialCode()
def gas
def engine = Engine(gas)
def body = Body(engine)
class SunnyRobot extends Robot
def gas = sun
class OilyRobot extends Robot
def gas = oil
Protocol extensions don't hold state. They are meant to provide default implementations for a type, not as a 1:1 relationship with the class it's implementing functionality for. Following what you're saying, I would be doing something like this:* `extension Robot where Self = SunnyRobot { def gas() = ... }`
* `extension Robot where Self = OilyRobot { def gas() = ... }`
That looks all good and well, right? Ok, well now my sunny robot wants to find the sun and my oily robot wants to go find oil. How to provide functionality unique to each of them? Maybe I'm just not getting something, but I'm pretty sure protocol extensions are not the answer to the problem I'm trying to describe.
When you're working in front-end land, you can do your best to stay functional and be cool and all that jazz, but it's just a waste of time usually. You're going to use a lot of state and you just have to learn how to manage that effectively (IMO). What this boils down to for me is that I might build a cell that does 3 things great and will be on every cell, but then business designs call for 2 slightly different cells still based upon that main cell. Oh and when those different cells are tapped, different things should happen.
So again, I just go about doing it with the simple base class gonna throw you an exception unless you override the "abstract" method. This way, I get to keep state going down and classes can actually fill up naturally rather than playing the protocol game.
class SunnyRobot : Robot {
func gas() { ... }
func findSun() { ... }
}Protocol extensions just don't cut it, I'm sorry. They're great for defining some default behavior and doing kinda-abstract-classes, but it's a different playing field in Swift/Obj-C than Java/Scala/C#/etc..
[1]: https://gist.github.com/jayrhynas/49945331e41314fc3ede
Edit: I just realized that with this method, the protocol extension is useless, you could just define `move` on Robot. So protocol extensions can give you a mix of abstract & default methods but if you need to inherit state you need to use a base class.
Apple really screwed up SpriteKit badly in the new version. I'm experiencing almost all of the problems mentioned in the forum.
It appears that most iOS devs who blog are using Swift.
My other guess is that it will come in time for ios 10 and be cross-platform ( aka work on mac os as well as ios).
I have absolutely zero inside info, but the fact is cocoa felts great and elegant on ios3 , but with all the latest additions it now starts to feel old and convoluted. Objective-c has been patched incredibly well but can only go so far, and the convergence of hardware between devices makes the distinction between computers and tablets more and more obsolete.
https://www.reddit.com/r/swift/comments/3kbjjn/so_swift_isnt...
We are still on track to open source Swift (including Linux support) "by the end of 2015" as promised, more details will come out when they can.
-Chris
My favorite feature of Swift's exceptions is the 'try' syntax required at the call site. This isn't like Java's try syntax: every call that may raise an exception needs a try, even if all you want to do is rethrow the exception. But the syntax is lightweight: just preface the call with 'try', it doesn't make a new scope. This makes the abnormal control flow explicit, addressing one of the strongest critiques of Java-style exceptions.
My second favorite features is the 'try!' syntax. This is the escape hatch: Swift's version of the empty-catch-block pattern of Java, except that it's 1. much more lightweight, because it doesn't introduce a new scope, and 2. the default behavior is to abort instead of swallow. It's perfect for non-production code like tests.
Regarding "you can't flatMap exceptions," I would respond that exceptions are meant to be exceptional, and this is what justifies the abnormal control flow. The do-try-catch syntax is an adequate substitute for flatMap, and more lightweight than requiring explicit unpacking of every return value ala Go.
But as you say, the hiding of type data is definitely weird. For those following along at home, Swift requires explicitly annotating functions that may throw errors, but not what those errors are, so you have to refer to the documentation. Also the compiler will complain if you don't have a backstop exception handler. Lastly, it introduces a magic variable 'error' that is defined within catch blocks: convenient but it feels ad-hoc.
antitypical/Result already provides Result.init(() throws -> T) -> Result<T, E>, so it's easy enough to work around, at least.
The magic variable stuff exists in didSet as well, weird and sketchy to use. Would prefer it to be explicit in all cases.