Swift Blog
developer.apple.com
developer.apple.com
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.
e.g. Adobe is contributing a lot of technology like CSS Regions
And Brent Fulgham maintain a Windows build of Webkit: http://whtconstruct.blogspot.com
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?
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.
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".
It's an unnatural forced use of the term expressly for that purpose, expressly saying something is not exactly what it is, isn't in anyway accidental.
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.
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.
https://twitter.com/mxweas/status/474581160454942721
> Max Weisel: Swift will be open source with the release of iOS 8 :)))
https://twitter.com/mxweas/status/474589964823306240
> Max Weisel: Asked at the labs
That said, as soon as I saw Swift was announced, I took the plunge and started my own journal about learning Swift.
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.
[1] https://developer.apple.com/devcenter/download.action?path=/...
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...
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.
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.
Neat :)
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.”Revision history for main book:
https://developer.apple.com/library/prerelease/ios/documenta...
[0] https://developer.apple.com/library/prerelease/ios/navigatio... and search for "swift". All the docs seem to have July dates.
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.
EDIT: also how to get character n in a string.
[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
You can also add your own String extension for length and index character at in a String with:
extension String {
var length: Int { return countElements(self) }
subscript (i: Int) -> String {
return String(Array(self)[i])
}
}
Which will now let you use `.length` on strings, e.g: "Cat".length; //3
And get the character at index with: "Cat"[1]; //a
I've more useful extensions at: https://github.com/mythz/swift-linq-examples/blob/master/src...Which enables LINQ-like querying in Swift: https://github.com/mythz/swift-linq-examples
countElements(string)
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. let codepoint: UInt32 = ...random choice code here...
let scalar = UnicodeScalar(codepoint)
let string = String(scalar) 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.
Short story: “number of characters” and “nth character” are more complicated questions than you might think when you deal with full Unicode text.
Looks like a great article, thanks!
-It's slow
-It's annoying for testing
-It's run by Oracle
-It feels antiquated
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!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.
operator prefix √ {}
@prefix func √ (value: Double) -> Double {
return sqrt(value)
}
√25 // Outputs 5.0
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.
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.
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.