We're very happy to welcome back one of our favorite sponsors again this week. It's buddybuild!
Long time readers will remember that buddybuild is a fantastic mobile continuous integration, delivery, crash reporting and feedback platform, all in one.
Thousands of development teams, like Slack, Meetup and The Washington Post love buddybuild because it's the easiest way to build, test and distribute their mobile applications.
It takes just minutes to set up, let's check it out!
We'll head over to buddybuild.com and click Get Started.
We'll sign up with Github (we could also use Bitbucket, GitLab, or sign up with email / password for repos on any other git server). Neat!
Next, buddybuild will let us choose a git repo to create our first project with.
Once we select the repo we want to build, buddybuild will get to work building our app for the first time.
After that build is complete, our app is set up on buddybuild - it's that easy.
buddybuild installs and configures the necessary web hooks for our project so new builds are triggered whenever code is pushed. It also scans your repo for any tests you might have written, and runs them reliably on the simulator and physical devices.
With buddybuild, we won't need to wait for App Store processing time or reviews before deploying to testers.
buddybuild's continuous deployment system can send our app to users instantly on every build, on a schedule that works for our team, or at the push of a button.
This kind of comprehensive Continuous Integration and Continuous Deployment workflow is a game changer for iOS and Android teams. It also means we can have our whole development workflow set up in just minutes. We can also infinitely customize and extendbuddybuild so it exactly just the way we want.
Buddybuild's deployment service also handles the process of adding new users (and their devices) by automatically managing UDIDs, iOS provisioning profiles and signing identities. (Fantastic UX for both testers and devs!)
Only buddybuild goes even farther, and gives us a fully integrated feedback platform.
Once users have installed our app and are testing it out, they can send their feedback (along with important diagnostic details) by simply taking a screenshot.
buddybuild also has rich pull request support. We can even pair it up with Danger to automate (the usually tedious) code review processes.
If our team works with pull requests frequently, buddybuild can be configured to build the pull request, then merge, commit, and update the commit status in GitHub, Bitbucket and GitLab. This ensures we always know before when a pull request is safe to merge.
If we have Unit Tests or UI Tests for our app, buddybuild will consistently and reliably run them as part of every build and automatically display how much of our codebase is covered by our tests. Neat!
If our app ever crashes, buddybuild's Source Context functionality will trace back and highlight the exact line of offending source code that caused the crash, telling us which users were affected, and how many times the crash happened.
Each crash is also recorded with an Instant Replay - this is a video replay of our users' actions in the moments leading up to the crash. Never wonder about "steps to reproduce" again! Super cool.
Buddybuild is also a great community citizen, and has our backs as iOS developers. For example, they'll give us a heads up on any potential breaking changes in Xcode. Within 48 hours of any Xcode release (including betas!), buddybuild will automatically takes our most recent successful build, and build and run tests against it using the latest version of Xcode. Then it will email us the results. How cool is that?!
Last but certainly not least, buddybuild not only comes with built-in integrations with tons of services we all know and love like GitHub, BitBucket, GitLab, Slack, JIRA Pivotal Tracker, Slack, HipChat but it's also infinitely customizable to meet the exact needs of your development team!
Swift 4 has brought with it a ton of great improvements. Today we'll cover one of them, it's the new Codable protocol! Codable ships with Swift 4 as part of the Swift standard library and allows us to conform our own types to it to get encoding and decoding functionality "for free".
Encoding and decoding types has never been easier.
Let's dive in!
Before we begin lets back up a second and look at what we're trying to accomplish when it comes to encoding and decoding.
Essentially we want to take an instance of an object or struct and convert (or "encode") it into some other, (usually "machine-readable") format. Then, later, we want to be able to convert (or "decode") the information in that format back into our object or struct.
These days the most common format for encoding/decoding is JSON. It's supported just about everywhere and has the advantage of being both human and machine readable.
For this reason, we'll be discussing JSON in this Bite. It's important to note though, that Codable isn't specific to just JSON. It's built to support encoding and decoding into just about any format we can think of.
In the past, we might have used something like the JSONSerialization class in Foundation to do encode our types into JSON.
This works great, but the encoding input and decoding output was either a Dictionary<String: Any>, or an Array of them. Then we'd need to manually convert to/from our "real" types.
With Codable, we can do much better!
Let's start with a simple struct conforming to Codable:
Nice. Now when we encode a Spaceship, the system notices that the pilot property's value is also Codable and does the right thing for us automatically:
This week we're welcoming back one of our favorite sponsors: It's buddybuild!
Long time readers will remember that buddybuild is a fantastic mobile continuous integration, delivery, crash reporting and feedback platform, all in one.
Thousands of development teams, like Slack, Meetup and The Washington Post love buddybuild because it's the easiest way to build, test and distribute their mobile applications.
It takes just minutes to set up, let's check it out!
We'll head over to buddybuild.com and click Get Started.
We'll sign up with Github (we could also use Bitbucket, GitLab, or sign up with email / password for repos on any other git server). Neat!
Next, buddybuild will let us choose a git repo to create our first project with.
Once we select the repo we want to build, buddybuild will get to work building our app for the first time.
After that build is complete, our app is set up on buddybuild - it's that easy.
buddybuild installs and configures the necessary web hooks for our project so new builds are triggered whenever code is pushed. It also scans your repo for any tests you might have written, and runs them reliably on the simulator and physical devices.
With buddybuild, we won't need to wait for App Store processing time or reviews before deploying to testers.
buddybuild's continuous deployment system can send our app to users instantly on every build, on a schedule that works for our team, or at the push of a button.
This kind of comprehensive Continuous Integration and Continuous Deployment workflow is a game changer for iOS and Android teams. It also means we can have our whole development workflow set up in just minutes. We can also infinitely customize and extendbuddybuild so it exactly just the way we want.
Buddybuild's deployment service also handles the process of adding new users (and their devices) by automatically managing UDIDs, iOS provisioning profiles and signing identities. (Fantastic UX for both testers and devs!)
Only buddybuild goes even farther, and gives us a fully integrated feedback platform.
Once users have installed our app and are testing it out, they can send their feedback (along with important diagnostic details) by simply taking a screenshot.
buddybuild also has rich pull request support. We can even pair it up with Danger to automate (the usually tedious) code review processes.
If our team works with pull requests frequently, buddybuild can be configured to build the pull request, then merge, commit, and update the commit status in GitHub, Bitbucket and GitLab. This ensures we always know before when a pull request is safe to merge.
If we have Unit Tests or UI Tests for our app, buddybuild will consistently and reliably run them as part of every build and automatically display how much of our codebase is covered by our tests. Neat!
If our app ever crashes, buddybuild's Source Context functionality will trace back and highlight the exact line of offending source code that caused the crash, telling us which users were affected, and how many times the crash happened.
Each crash is also recorded with an Instant Replay - this is a video replay of our users' actions in the moments leading up to the crash. Never wonder about "steps to reproduce" again! Super cool.
Buddybuild is also a great community citizen, and has our backs as iOS developers. For example, they'll give us a heads up on any potential breaking changes in Xcode. Within 48 hours of any Xcode release (including betas!), buddybuild will automatically takes our most recent successful build, and build and run tests against it using the latest version of Xcode. Then it will email us the results. How cool is that?!
Last but certainly not least, buddybuild not only comes with built-in integrations with tons of services we all know and love like GitHub, BitBucket, GitLab, Slack, JIRA Pivotal Tracker, Slack, HipChat but it's also infinitely customizable to meet the exact needs of your development team!
This time of year it's common to have multiple versions of Xcode installed.
Today we're going to learn how to tell our system which version of Xcode's tools to use when working with Xcode from the command line. But first we'll check out a helpful tool to actually installXcode from command line.
Let's dive in.
The first tool we'll look at can be used to install Xcode versions directly from the command line. It's an alternative to using the Mac App Store (or just managing downloads manually).
By default, xcode-install only prints the last few major versions.
(Sidenote: For fun and nostalgia try running xcversion list --all to print all the available versions of Xcode going all the way back to 4.3 for OS X Lion 😱).
We can install a version like this:
xcversion install "9 beta 4"
We'll be prompted for our Apple Developer credentials which will be stored in our Keychain, and then the version will be download, installed, and moved into place, all without leaving the command line.
Next we'll need a way to switch to the new version we just installed.
The tool we'll be working with is already installed on our Mac and is called xcode-select.
It's a straightforward, single-purpose utility that essentially controls which path on disk gets run when we run xcrun, xcodebuild, etc. from our command line.
Let's first check out which version of Xcode we're currently using:
xcode-select --print-path
Which (by default) will print:
/Applications/Xcode.app/Contents/Developer
(Note: This is what's printed for versions of Xcode installed from the App Store).
Next, lets take a look at all of the versions of Xcode we currently have installed.
Here we're going to grep for Xcode inside of our /Applications directory:
Today we're going to take a look at how we can control (and interact with) the iOS Simulator from the command line.
There's no need to install anything new though. The tool we're going to be using is already on our Mac, hiding inside the xcrun command, which gets installed with Xcode.
It's called simctl.
Let's begin!
First thing we'll want to do is tell simctl to print out a list of our current iOS Simulator devices. We can do that by running:
xcrun simctl list devices
This will print a list of all the simulated devices and a UDID value with each:
-- iOS 10.3 --
iPhone 7 (C4481459-5BB1-4CE1-9BE0-CF0FEA351299) (Booted)
iPhone 7 Plus (ADCB6F99-5ADD-49B1-83AE-5391D845C4D0) (Shutdown)
iPhone SE (FB0899C0-5812-492E-80D9-9DE517554C12) (Shutdown)
iPad Pro (9.7 inch) (45F47977-9A03-4DD1-8FD0-289F7936FE98) (Shutdown)
iPad Pro (10.5-inch) (C3C909DC-BF70-4D67-BF7E-A41A0CF4AF56) (Shutdown)
...
We can see by the (Booted) notation next to the first device that simctl has identified the iOS Simulator we had open at the time of running the command.
We can pass that UDID (C4481459-5BB1-4CE1-9BE0-CF0FEA351299) to other commands to target our currently running iOS Simulator.
For shorthand though, we can also just pass the term booted to target the currently running iOS Simulator.
(Note that in Xcode 9 multiple iOS Simulators can be running at once. If we pass booted in this case, simctl will just choose one for us).
Whew. Ok with that introduction out of the way let's try this thing out.
First up, one of the best features of simctl, opening URLs.
To open a URL in the iOS Simulator, from the command line, all we need to run is:
We can include one or more file paths here. It supports images, videos, and even Live Photos.
After running, the files will be imported and appear in the Photo Library:
Next: iCloud Syncing.
We can explicitly force a sync of iCloud using this command:
xcrun simctl icloud_sync booted
What's nice about this is we'll even get errors printed if (for example) iCloud isn't yet configured in this simulated device:
An error was encountered processing the command (domain=BRCloudDocsErrorDomain, code=2):
The operation couldn’t be completed.
(BRCloudDocsErrorDomain error 2 - Logged out - iCloud Drive is not configured)
This next one's a doozy. We can use simctl to record and stream live video, and capture screenshots of any screen of our iOS Simulator.
The recordVideo subcommand's output can be | (piped) into other commands or even to a TCP or UDP socket for live streaming. This works on all iOS, tvOS, and even watchOS Simulators. Very cool.
Last but not least, we can print out the path for app's installation directory on disk:
Asset Catalogs have been around for a few Xcode releases. They're a great way for us to organize and configure graphical assets (among many other things) for our app. Today we'll check out the improvements to Asset Catalogs in Xcode 9. Let's dive in.
First up, colors.
Yep, we can now define and organize named colors inside of an Asset Catalog!
We can select "New Color Set", and then use all of the normal features of Asset Catalogs, including new Wide Gamut support.
Then, in our code we can reference these colors like this:
view.backgroundColor=UIColor(named:"wood")
Neat!
The second big addition we're going to look at is "real" vector-based asset support.
In past Xcode releases, we were able to add image assets to our catalogs with a format of PDF. This worked great, but under the hood, Xcode would simply render our asset at the @1x, @2x, and @3x sizes and save non-vector (i.e. png images) into our app's bundle.
In Xcode 9 however, we're given a beautiful new checkbox called "Preserve Vector Data".
This means that if our image is loaded in our code, and we ask it to display at a a larger size than it is by default, it will be scaled up at runtime by the system.
This means we can now write code like this without any quality loss at render time:
We're welcoming back one of our favorite sponsors this week, it's Zendesk!
None of us have ever built a flawless app.
Chances are, no matter how good we think our app's user experience is, there's probably something users will need help with while they're in our app.
Yet in many apps, getting help is reduced to a "contact us" button that launches an compose email screen, or a just drops the user on a web page.
By forcing folks out of the app to get help, small problems can turn into big annoyances, and those will almost certainly turn into negative App Store reviews and poor ratings.
Today we're going to talk about corners. Specifically, rounded ones. In iOS 11, Apple has improved the way we can specify and work with the rounding of our views' corners. Let's take a look.
Let's begin with where we were before iOS 11.
Before iOS 11, configuring a UIView to have round corners went like this:
The clipsToBounds ensures the "clipping" takes place, and the next rounds all four corners with a radius of 8:
Pretty straightforward.
This approach works great for rounding all four corners of a view. But what if we wanted to round only some of the four corners? Previously we'd need to drop down and create our own mask layer, giving it a path we created manually. Bummer.
Now we can use the new CACornerMask option set to specify which corners we'd like rounded. Here we've asked for just the bottom two corners to be rounded with an 8 point radius:
Neat!
Before we go, there's one last thing to know about round corners in iOS 11:
They are now completely animatable! 🎉
In previous releases, this next bit of code wouldn't do anything, but in iOS 11 this works exactly as expected:
We're welcoming back one of our favorite sponsors this week, it's Zendesk!
None of us have ever built a flawless app.
Chances are, no matter how good we think our app's user experience is, there's probably something users will need help with while they're in our app.
Yet in many apps, getting help is reduced to a "contact us" button that launches an compose email screen, or a just drops the user on a web page.
By forcing folks out of the app to get help, small problems can turn into big annoyances, and those will almost certainly turn into negative App Store reviews and poor ratings.
Continuing our look at the new tidbits and goodies from WWDC 2017, today we'll learn about the changes to screen edge behavior in iOS 11. Let's dive in.
What we're really talking about here is the behavior when a user drags from offscreen. This could be the user trying to pull down Notification Center from the top, or bring up Control Center from the bottom of the screen.
In past iOS releases, the system has looked at the visibility of the status bar to determine how to behave in these cases.
If we configured one of our view controllers to hide the status bar, the system would show a little "tab" UI with an arrow that the user would need to drag a second time before Notification Center or Control Center would be shown:
Keying off of the visibility of the status bar probably isn't the best way for us to "tell" the system what to do here.
In iOS 11, we've been given a wonderful new way to describe how our app should behave when the user performs these gestures.
Now, all we need to do is override this function in our view controlller:
This way, we can describe exactly which edges of the screen we'd like to allow the system gestures to behave "normally", and which we'd like to have defer for a second drag. Neat!
Finally, if the state of our view controller ever changes enough to warrant a change in this behavior, we can call the following new function to update it: