I have been collecting resources together for everything I come across on Apple Swift. ?I add these to a new Flipboard magazine called Swift Development. ?If you come across interesting links you feel should be in the magazine, pass them along to [email protected].
Swift has a very nice Read-Eval-Print-Loop (REPL) for developers to take advantage of and be able to get instant feedback on Swift code. ?This is great for trying things out without having to use Xcode 6 and a full project.
If you are unsure of what this REPL is, from the Swift web site:
Read-Eval-Print-Loop (REPL). The debugging console in Xcode includes an interactive version of the Swift language built right in. Use Swift syntax to evaluate and interact with your running app, or write new code to see how it works in a script-like environment. Available from within the Xcode console, or in Terminal.
The problem is, it?s not available by default since it?s not in your path. ?If you have Xcode 5 installed you probably don?t want to have to deal with switching back and forth between Xcode paths.
The solution is pretty simple actually. ?I wanted to be able to get to Swift from the terminal with a short command, in this case, swift will be the command. ?In order to setup it up I located the swift binary, yours may be different depending upon where you have the Xcode 6 beta installed. ?Mine was here:
If you just run that line in terminal it works fine but I want to be able to access this easily. ?The answer is an alias added to the .bash_profile. ?Add this line to the .bash_profile:
Restart the terminal app, type swift and you should see something like this:
UPDATE (06/17/2014): Apple released Xcode 6 Beta 2 today and the path changes to where the Swift binary lives, use Xcode6-Beta2.app instead of Xcode6-Beta above.
I haven?t blogged here in a while, sometimes life seems to get in the way.
Last week I was one of many who watched the Apple WWDC keynote and was blown away by many of their announcements. ?The one to get me the most excited is the new programming language, Swift. ?No one saw this coming.
I?ve been a long-time Objective-C developer but have never been in love with the language. ?As Apple developers, we use because it?s the only real option?until now. ?Swift is introduced as an alternative to Objective-C, not a replacement, and to me resembles Go and C# with many of the language constructs. ?I?m not going into the language details today but you can find out more from The Swift Programming Language guid in the iBooks Store.
Swift is a type-safe and modern programming language for Cocoa and Cocoa Touch applications, which means targeting iOS and OS X. ?It?s really nice to see Apple making big changes and offering developers a choice. ?I?ve read tweets and other reactions to Swift and asking why we need another programming language but I say it?s a good thing. Swift does away with all the square brackets () and pointer references to create a cleaner programming language. ?
Should You Learn Swift?
Objective-C isn?t going away any time soon. Apple realizes Objective-C has baggage and when looking at adding to the language, there is only so much they can do with it and therefore came up with a language that removes all of the warts on Objective-C. ?The API?s are the same when using Cocoa and Cocoa Touch so if you are an Apple developer already, you are half-way there.
Apple releasing this new language says a lot; it expresses Apple?s intentions. ?Swift will be important in the future, whether that?s a year or five, we just don?t know.
Yes, I think you should learn Swift. ?If you are new to Apple then you have a choice, Swift or Objective-C. ?Aaron Hillegas, long-time Objective-C proponent, thinks developers need to know Objective-C. ?He has some valid points:
You can’t do everything in Swift. For example, if you want to use a library of C++ code in your application, you will need to talk to the C++ objects from Objective-C. Swift can call C functions, but I believe that if you are working with a lot of C functions and types, you will want to code in Objective-C.
He claims Objective-C is easier to learn than Swift. ?I?m not sure I agree with this point:
C is a really simple little language, and Objective-C is a really simple little extension to C. Swift has many rules that Objective-C does not. (I, as an instructor, am already trying to figure out how I will explain the rules around optional variables and the proper use of ? and ! to signal the programmer’s intent around optionality.) These extra rules mean that the compiler can be much more pedantic about enforcing good coding practices, but it also means that the language will take longer to learn.
Objective-C requires programmers to be explicit. The Swift language lets the compiler do more work for the programmer. This is great?less typing for the programmer, right??but it means that when you look at a line of code, it won’t mean much without a deep understanding of the context in which that line lives. Explicit languages are easier for beginners to understand.
Swift has a bunch of constructs that Objective-C doesn’t have. For example, generics make type checking better in Swift, but it makes that language considerably more complex.
Marco Arment had a good follow-up to Aaron?s post and I tend to agree with him:
The time will come when knowing Objective-C will be like knowing C, C++, or assembly ? it?ll be a plumbing layer beneath your application code that almost all working developers will never need to know or interact with. And I bet that time is less than five years away ? possibly just two or three.
I have to say that as far as sample code, blog entries and Stackoverflow threads, Objective-C will have the lead for a long time. ?Finding solutions to problems specific to Swift will be harder to find and you might be a bit of an explorer for a while.
If you are targeting multiple platforms there is always a debate. ?If you go native on every platform then Swift may be a good choice. ?If you like the idea of a single-ish code base then maybe Xamarin (C#) or RubyMotion is something to consider.
If you want to play with Swift be aware that you will need the Xcode 6 beta.
I am devouring the Swift documentation and WWDC presentations. ?Over the next few months I will be blogging about it, now that I have a good reason to blog. ?
I will not be migrating any Objective-C code bases to Swift?I don?t see the point. ?I will be writing sample code and creating a new application with only Swift and plan to document the process.