Wow, this is an interesting/refreshing development from Apple. I can't recall them ever having a public blog to communicate with their developer community. Until now, it's mostly been through their developer forums, private support, and in-person at the yearly WWDC.
How they've developed as a developer-facing company this year is really encouraging. Google et al have always been transparent as glass relative to Apple's iOS work, but this blog, the twitter dialog from Swift's development team, and the no-NDA release of iOS8 has really changed my opinion of the direction they're pushing the ecosystem.
Surfin' Safari (https://www.webkit.org/blog/) is another great Apple developer blog. I followed it religiously back when Webkit was leaving everyone else in the dust.
Well, let's just wait and see, because frankly, I'm tired of reading marketing fluff like "We can’t wait to see what you build!".
After years in the making (which means plenty of time to think of an answer), one of the most important questions still hasn't been answered, and not even mentioned on the blog.
Namely, will Swift be open-source and submitted to standards bodies? Will key libraries also be released?
If I make an investment to learn Swift, what are the chances that I can take this knowledge and use it outside of the Apple ecosystem? Or is Swift destined to follow the fate of Objective-C and be completely useless outside of Mac/iOS apps?
I may yet be disappointed but I'm expecting them to open source it after release as they do with the other LLVM changes they make.
I think it could work with anything based on C libraries (C++ linkage sounds a bit trickier) but it has been very much designed to operate with the Obj-C libraries.
It might be that Haskell is a language to learn and may help you develop functionally if you switch to Swift later. There isn't that much to learn about Swift itself really.
Seems fairly transparent: members of the team would like to make it open source closer to the release, but they haven't made a decision yet and will likely do so once the 1.0 release is complete.
I did phrase that terribly. What I meant (and failed) to convey was that the most authoritative source of info on this topic was a post to a relatively obscure LLVM-related mailing list, rather than any sort of official announcement. However, I shouldn't have said "lack of transparency", because the devs could have chosen to not make any sort of public statement at all.
Considering that Swift is built on LLVM, it's not surprising that a comment was made there. It's also probably where an announcement of it being open source would be made (and now probably the Swift blog).
I've heard from various people that any decision on open source wouldn't happen until after 1.0 since the language syntax decisions haven't been nailed down yet.
Interesting thread. Not buying Chris's (with his Apple hat on) answer though.
The idea that you spend a few years to create a new language and have not even had a discussion yet about whether or not it will be open source is simply not credible.
Unless Swift was rushed to release because companies like Apportable were making too much progress and they wanted to herd developers back into the pens with new proprietary languages and APIs e.g. Metal.
Maybe they just don't want to deal with open sourced stuff for 1.0 Reference the arm64 stuff, I bet that the situation is that swift is in heavy flux (which if you follow Chris Lattner on the apple forums you realize they're changing things like crazy right now) and they just don't want to deal with people contributing to something that isn't quite ready. They already committed to saying they will introduce breaking changes in future releases. Maybe the whole team just doesn't have the time to deal with it, who knows, lets wait. Its not like C# suffered by not being open source from the start.
I wouldn't put that past Apple. Remember the more we antagonize them the more likely their legal team might go "not worth the effort just keep it in house".
Have you ever worked at a company that open sources code? I mean it's fairly common, even VERY common that the devs are all for open sourcing the product but the legal department has not made a decision yet. Engineers move at an incredibly swift, no pun intended, pace but Lawyers tend to take glacial ages to decide anything. It's completely and totally credible that the legal department hasn't given their final ok on things, especially at a company like Apple and as large as Apple is.
Figured I'd document my progress as I went along and it's been a lot of fun so far. This is something I plan on doing over the long haul and I'd like to get in some small 5-10 min videos that covers not only the language but also new things coming out in XCode as well.
I'm two posts behind, but I'm trying to release a new post every week. My biggest slow down has just been figuring out the blogging software and hosting.
I am currently downloading XCode 6.3 Beta [1] without being a registered developer (used my ordinary credentials), does that mean that I will be able to write applications and play with the REPL? Has it just been made available?
Would've been nice if they'd done this from the start (says someone who just paid his registration fee last month solely for access to the new XCode beta/Swift) but better late than never. Maybe there was some strategic value in only letting paying devs have access it for the first month or so as the news settled in...
Beta 1 was really pretty flakey and Xcode tended to crash every 20 minutes or so. Beta 3 is much better. I suspect the quality and readiness for a potentially less friendly audience is what caused them to keep it to registered devs rather than an attempt to get more cash.
Hopefully you end up getting some value from your registration. You could always ask for a refund but I don't know if they would give it to you.
> I suspect the quality and readiness for a potentially less friendly audience is what caused them to keep it to registered devs rather than an attempt to get more cash.
Probably true.
> Hopefully you end up getting some value from your registration.
Definitely got some value :) For one, I had the time to play around with it last month, that I don't have this month, so for that alone it was worth it. So not bitter about it!
Count yourself lucky, that's probably not going to last long. Xcode itself doesn't do any server side verification of your developer status to let itself run, so you'll be able to do everything aside from sign and sell apps.
It's really great to see Apple opening up - maybe not in their products, but in their culture. Programming language blog, a presence on social networks (mostly Twitter), posing for pictures with devs at WWDC, and generally embracing the dev community. All of these individual things seem small but together show a much more open side of Apple.
A side effect of these changes: Apple can control their own story now; whereas the rumor mill and the Apple-Needs-To-Release-A-New-Category-In-The-Next-30-Days-Or-They-Are-Doomed websites have been controlling their story/image for the past couple years.
let interestingNumbers = [
"Prime": [2, 3, 5, 7, 11, 13],
"Fibonacci": [1, 1, 2, 3, 5, 8],
"Square": [1, 4, 9, 16, 25],
]
var largest = 0
for (kind, numbers) in interestingNumbers {
for number in numbers {
if number > largest {
largest = number
}
}
}
largest
Excerpt From: Apple Inc. “The Swift Programming Language.”
Note that if you downloaded the original book into iBooks you need to delete it and download it again to get the version that matches Beta3 (fixed array semantics and new range operator ..<)
I like the idea of a blog, something where I can get official news and tips from is great. Perfect supplemental reading for all those blogs run by outside developers. I look forward to using Swift.
Also, for those that may have missed it, you can use Swift in XCode 6 beta, so long as you are a registered Apple Developer.
There's been a lot of prior discussion about Swift on HN. I think the general consensus is that it's a fun and somewhat-well designed language that's buggy in places but will eventually make a good Objective-C replacement. I personally have enjoyed playing around with it. If Apple open-sources it, I could see using it as my main language (to replace Java, which I hate).
Swift can call Objective-C APIs, so if you're building Mac or iOS apps, you'll get access to the full Cocoa API. You can't build iOS apps in Scala (as far as I know) and I've never been a fan of Java GUIs.
If you want a strong resemblance, Swift looks spookily like Groovy - to the point where I have to actually check sometimes that I'm not reading Groovy code. I would say much more so than Scala.
let maximumNumberOfLoginAttempts = 10 // let keyword
var currentLoginAttempt = 0 // var keyword
var welcomeMessage: String //type postfixed after colon
if turnipsAreDelicious { // no parens around if-condition
println("Mmm, tasty turnips!")
}
let http404Error = (404, "Not Found") //tuple
println("The status code is \(statusCode)") //interpolated string uses \( ... )
I don't think the syntax looks like Groovy at all!
Yup. Everyone has different needs from their code, an mine primarily needs to run on Linux despite often working on it in OS X. Ruby does that beautifully now. I can't see spending time on Swift until it runs across Unix flavors. That seems quite possible in principal since Swift relies on LLVM.
Yes. I've built two apps on it. One is an Emoji Social network like Yo, but with Emojis, and the other is a Weather app that uses forecast.io.
This is what I've been telling everyone. Swift does not make most of iOS App development easier; For the average person, the only benefit your'e going to get is no header files and 0%-30% shorter class files. The majority of iOS is about learning the libraries and API's. The main benefit of of Swift for the common user are that you can easily define and use your variables without giving them a type. There are also some niceties in Swifts functional programming style. As a developer on the iOS platform for the past 6 years, my problems were never with obj-c, they were with all of the "other stuff."
If you don't understand how to layout an app and use a UITableViewController correctly, Swift doesn't help. If you don't understand the delegate callback or segue design patterns, Swift doesn't help. If you don't understand the PKI required to create your Dev and Prod certificates, Swift doesn't help. If you don't don't know to use Interface Builder to connect your UI's to your controllers, Swift doesn't help. If you don't know what keys to put in your info.plist to tweak the status bar or import certain settings, Swift doesn't help.
Now from the advanced developer perspective, Swift is amazing. If you have a chance to watch Apple's advanced Swift talk (404 Advanced Swift), that's where you really see the power of the language come into it's own. You can literally re-write the language with the language. Mattt Thompson published a public gist[1] a few days ago where he showed how you can define mathematical constructs of unicode characters that aren't natively defined in the language. So for example, you could define the symbol square root.
Obviously, you'd have to do a bit more work on that to handle negative square roots and get into imaginary numbers, but things like this give you a glimpse into the power of the language. The real power of Swift is probably not going to be used by a lot of app Developers, but the potential of the language is a lot better than Objective-C ever had.
Plus, you can now use emoji's as variables so that right there is worth learning it.
> If you don't understand how to layout an app and use a UITableViewController correctly, Swift doesn't help. If you don't understand the delegate callback or segue design patterns, Swift doesn't help. If you don't understand the PKI required to create your Dev and Prod certificates, Swift doesn't help. If you don't don't know to use Interface Builder to connect your UI's to your controllers, Swift doesn't help. If you don't know what keys to put in your info.plist to tweak the status bar or import certain settings, Swift doesn't help.
So I learned Swift in like a day, but all that stuff you listed I have absolutely no clue about. I just began iOS development and it's kind of overwhelming to open Xcode for the first time to see 57 different panels with 33 options in each panel (compared to opening Vim for instance haha).
What would you recommend as a good resource for learning the "correct" way to use things like UITableViewController? Of course I can hack together an app that functions well enough but I'd like to use the API in the proper, idiomatic way if possible.
The best way to learn correctly is to have someone who knows what they are doing sit next to you and explain what's going on with the IDE. I did this last week with this cool dev @firebase and it was great. I just told him what to click, what to press, where to go, how to set stuff up, and he did all of the controls. He learned the IDE, and how to build a project.
Second best way to learn would be to check out Apple's code samples and training videos. They usually have good syntax and proper usage although most of Apples examples are in Objective-C right now. They still give you a good understanding of what's going on. Taking an online class is also another avenue I would place at the same level as code samples. If you can find an online class that you find interesting, that's another way to get familiar with xCode.
Third best way would be to look at examples on cocoacontrols.com or github.com for code examples. The only challenge with this is that you might not get the best code structure as a lot of developers are just copying/pasting from other code and aren't really architecting their software correctly. That being said, you can still find code that works.
I've been using it for my latest project. Haven't done anything too fancy with it yet. Lack of automatic type conversion between ints and floats is driving me up the wall a little bit, but maybe that's a personal flaw rather than a flaw with the language. String manipulation is also incredibly confusing to me: I have yet to figure out how to get the number of characters in a string, or how to generate a random character. Other than that, it feels pretty nice to use.
.utf16count will get you the number of characters in a simple string[0].
[0] What is a character especially in various non-latin scripts? I think it is well handled in Swift, from what I can see it has been considered carefully but I haven't yet needed to get my head round it.
Edit: Corrected - too fast in the playground and actually checked an array. .utf16count not .count
returns the number of Unicode code points in a string. I'm not sure about the random character, though. Swift is very much oriented towards Unicode rather than bytes when it comes to strings.
To get the number of characters in a string, call countElements(string). To generate a random character, your best bet (IMO, someone else may have a more elegant solution) is to have an array (or dictionary) or characters and use a random number generator to select a character from the structure.
If you have a range of unicode code points that you want to select from, you can generate a random number in that range and then turn it into a one-character string like so:
let codepoint: UInt32 = ...random choice code here...
let scalar = UnicodeScalar(codepoint)
let string = String(scalar)
It would be easier to do this from an array of strings but I found an ugly inefficient way to do it from the characters in an arbitrary string:
func randChar(alphabet:String?)->String {
let alpha = alphabet ? alphabet! : "abcdefghijklmnopqrstuvwxyz"
let rand:Int = Int(arc4random_uniform(UInt32(countElements(alpha))))
var gen = alpha.generate()
for i in 0..<rand {
gen.next()
}
return String(gen.next()!)
}
mikeash obviously has the answer if the codepoints are consecutive.
This was quite annoying to do, more so than I expected. If you convert to UTF16 view you can alter the index by advanceBy but then I couldn't find an easy way to convert back from the UInt16 to a Character/String but mikeash also covers that. However I'm not sure that conversion to UTF16 is any less work internally than iterating through the index.
How they've developed as a developer-facing company this year is really encouraging. Google et al have always been transparent as glass relative to Apple's iOS work, but this blog, the twitter dialog from Swift's development team, and the no-NDA release of iOS8 has really changed my opinion of the direction they're pushing the ecosystem.