Why is it so hard to parse JSON in Swift? I can’t count the number of times I’ve seen or heard this question since Swift came out. So what’s the problem? Shouldn’t a real programming language make it super simple to work with JSON since everyone uses it everywhere? The issue is that we’re taking weakly-typed JSON data and transforming …
Cut your Swift build times in half with this one weird trick
(I’m not apologizing for the clickbaity title since it actually works and it is a little weird…) I’ve been working on improving Swift build times off and on for the past few weeks, and today I stumbled across the best possible improvement: a one-line change that cut our build times in half. I noticed in our build logs that all …
Testing asynchronous code in Swift with XCTest expectations
Testing asynchronous callbacks in your Swift code? Try this: let expectation = expectationWithDescription(“Get some sandwiches!”) let client = SandwichClient() client.getSandwiches { result in switch result { case .Success: expectation.fulfill() // ? case .Failure: XCTFail(“Expected getSandwiches to succeed, but it failed. ?”) } } waitForExpectationsWithTimeout(10, handler: nil) Consider using OHHTTPStubs or just stubbing manually to make this run faster. (Note that …
WWDC 2016 podcast episodes for iOS developers
I enjoy listening to podcasts when I commute, and I especially love hearing different people’s thoughts, opinions, and recommendations on what to do as a result of the new announcements at WWDC. Here are some of the WWDC 2016 podcast episodes I’ve enjoyed, followed by a few that are still on my list. If you’re looking something to listen to …
Key takeaways for iOS developers from the WWDC 2016 Platforms State of the Union
The Platforms State of the Union at WWDC is a great way to learn about some of the new features available to you as an iOS developer as well as improvements to Xcode that’ll make your life better. But it clocks in at nearly two hours, so if you don’t have that much time to spare, read on for the …
Key takeaways for iOS developers from the WWDC 2016 Keynote
As a busy iOS developer, it’s hard to find time to sit down and watch a two-hour keynote, even if it is relevant and important. Here’s a summary of what Apple announced in the WWDC 2016 Keynote as it relates to iOS developers. This covers only what’s relevant to you as an iOS developer; it doesn’t cover watchOS 3, macOS …
Navigating Apple’s WWDC from home
Not going to WWDC? Here’s what you can do next week to keep up with all the important new announcements — even if you can’t take the entire week off to watch the videos from home… ‘cuz let’s face it — we’re all too busy for that. Most importantly, you want to pay attention to the Keynote and the Platforms …
How do you unit test REST calls in Swift?
In the Live Q&A chat Christina and I hosted a few weeks ago on GrokSwift.com, Steve asked about the best way to unit test REST API calls. Here’s his question: Can you talk about the right way to unit test rest calls? What are the best tools for just testing endpoints? I love this question — probably because I love …
Recipe: Using Anchors to Place Views in iOS
I just learned anchors for placing views in iOS, and they totally blew my mind. If you’re setting any auto layout constraints programmatically with NSLayoutConstraint’s constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:, you know how ugly and verbose it can be – and you definitely want to check out anchors. Want to center your segmented control horizontally 20 points from the top of the view? Forget …
Avoid using class names in Swift’s #selector
Don’t use class names in Swift 2.2’s new #selector. In other words, don’t do this: button.addTarget(self, action: #selector(MyViewController.showLoginView), forControlEvents: .TouchUpInside) Here’s the problem: it compiles, so you’d expect it to work, right? Isn’t that what #selector is all about? But let’s say you decided to refactor this code out of MyViewController and into a child view controller called MySecondViewController. (This …