Swift Around the Web
This week's must-reads include great summaries of XCode 6 Beta 6 changes, examples of how to use Swift functions and arrays, and of course I had to throw in a Swift JSON parsing with functional programming blog post in there :)
Changes in the Swift Standard Library in Beta 6
A detailed explanation of the Swift Standard Library changes in XCode 6 Beta 6. I've been enjoying using the nil-coalescing operator ?? in my code, so this change stands out to me - "The ?? operator has been updated to include a version to explicitly handle both the LHS and RHS being of the same optional type."
Swift, Xcode: There are many betas. I am number 6. You can call me "Caprica 6"
Erica points out that in Beta 6, hasValue has been removed. I actually didn't know about using optionalValue.hasValue {...} to check whether an optional does have a non-nil value, but right after reading Erica's post, I came across multiple points in my code where I immediately wished it was back!
Facets of Swift, Part 4: Functions
I was preparing my own presentation and blog post about Swift functions, when Tammo came out with Part 4 of his amazing Swift series. Swift functions have a lot of variety (maybe too much?), which makes them very powerful yet definitely confusing if you're coming from a programming language with very straight-forward functions. Tammo does a great job explaining Swift functions, clearing away some of that confusion.
Arrays and their Methods in Swift
This is a great overview of how to use Arrays in Swift. I didn't know that one way to add an element to an array looks like this: myArray += [5]. Looks weird to me, so I'll just use the append method!
Functional Wish Fulfillment
"Yes, this is another of those 'how to parse JSON in Swift' blog posts that seem to be required of every Swift blogger. And yes, several of the techniques we’ll work through come from the functional programming world. And, yes, Swift+Functional+JSON is itself a well-worn trail." Love these blog posts, keep them coming!
Apple News
Beta 6 is out!!!!!!! What stood out from this release is that changes included a lot more bug fixes / optimizations versus the major changes we've been seeing in the Swift language between betas until now (like re-writing how Swift arrays work!).
Don't get me wrong though, these bug fixes / optimizations are definitely major. I've been feeling the pain of this one in my Swift projects:
A large number of Foundation APIs have been audited for optional conformance, removing a significant number of implicitly unwrapped optionals from their interfaces. This clarifies the nullability of their properties and arguments / return values of their methods. This is an ongoing effort since beta 5.
Another thing to note is that there was no new iOS8 beta released. Does that mean Apple is getting ready to do an official release next? I don't know!
Here are the Beta 6 goodies:
Oh, and don't miss these great blog post from the Swift Blog!
Other Cool Stuff
Ok, so maybe I'm late to the game, but did you know that Command + Control + Space brings up the emoji keyboard on your mac?!! Now I can write some real Swift code, lol. Special thanks @tammofreese for helping me figure it out!
In Case You Missed It
I have many blog posts lined up that I haven't had a chance to write just yet due to travel this week. However, I'm glad the one blog post I did have time to write was about Swift Debugging. I also just posted slides from my talk at GoModev about Swift Functions. Enjoy!
Swift Code
Wohoo!! Swift Playground Builder empowers you to create Apple-like playgrounds with your own fancy embedded documentation. In addition to the playground builder, this week's libraries are focused on extending Swift in fun ways. Love looking through the code in these libraries!
- Swift Playground Builder - Create your own interactive Swift playgrounds with embedded documentation compiled from Markdown
- Dollar.swift - A functional tool-belt for Swift Language similar to Lo-Dash or Underscore in Javascript
- AFDateHelper - Convenience extension for NSDate in Swift
- [ExSwift(https://github.com/pNre/ExSwift) - A set of Swift extensions for standard types and classes.
- CryptoSwift - Bunch of crypto related functions for Swift
Swift Thoughts
The most exciting Swift-y thing I did this week was figure out how to properly write Unit Tests in Swift. Yes, I'm one of those developers who gets excited about Unit Tests :) And yes, I'll make sure to blog about my experience and challenges working with the XCTest framework in Swift this upcoming week, so make sure to follow my blog (RSS feed available here).
The first big challenge to writing unit tests in Swift was access controls. Since unit tests are in a different target than the project code, the code you'd like to test either needs to be made public, or it needs to be added to the test target. Andrew Bancroft outlined these two options in his very helpful blog post: Swift Access Control – Implications for Unit Testing.
I'm guessing Apple will fix the access control issue in future releases, so I like the second option - adding my code to the test target. It's going to be much easier to remove files from the test target if needed than having to make variables and functions public individually just for testing purposes.
If you haven't looked into testing your iOS code yet, I highly recommend reading the latest issue of objc.io - Testing.