Swift Regex Deep Dive
iOS MacOur introductory guide to Swift Regex. Learn regular expressions in Swift including RegexBuilder examples and strongly-typed captures.
It’s an overplayed metaphor, but it fits: I can’t find any way to describe the iconic keynotes at Apple’s Worldwide Developer Conference (or WWDC) without comparing them to opening Christmas presents when I was a little kid. If you’re lucky enough to go to the conference, I can’t recommend the keynote highly enough—the excitement from attendees and presenters is palpable. Few in this community get to go to the conference at all, or get to blow off a Monday to discover the ways in which our work will change over the next few months.
But that’s the Big Nerd Way: we absorb everything Apple has to offer, do the hard work of discovery while new technologies are being developed, learn how to do things quickly and share that knowledge you.
The theme of this year’s announcements is one of incremental refinement. Absent are the earth-shattering changes of new paradigms or entire languages. The landscape of iOS and OS X aren’t changing dramatically; rather, everything is getting a bit better. If you feel like your investments in yesterday’s new technologies like Auto Layout, Storyboards or WatchKit weren’t paying off, now is when that investment will bear fruit. If you aren’t familiar with these technologies yet, be sure to check them out before the end of the year. In the meantime, let’s get into the changes in more detail.
Some changes to the ecosystem present a clear roadmap for the future. The iPad, for instance, is getting versatile multitasking features: applications can run side by side with one another, requiring your apps to be even more aware of the resources and layouts they use. The writing has been on the wall since WWDC last year: if you do nothing else, you should be adopting flexible layout. Every app should be built with universal layout in mind, because there will only be more combinations of screen size and shape from here on.
WatchKit has graduated from a part of your iPhone app to a full platform of its own, with watchOS getting full tooling to sit alongside OS X and iOS. We’ll have more to say about this soon, but rest assured that the transition will be smooth. The effort and code invested into WatchKit translates nicely into full Watch Apps. But if you haven’t touched WatchKit yet, new features like sensor access might be the functionality you were waiting for.
App Thinning is a group of features allowing apps to take up less space on a user’s device and run faster.
If you’ve ever had to rush to put out an update for a new iPhone or iPad release, these features should make you excited. In a well-engineered application, you may only need to release updates to support new OS features, not new hardware.
Other changes coming this year aim to fix long-standing pain points. Take, for example, your app’s layout. Complex, engaging UI used to require complex layout, like elements that hide or show, or siblings that have distributed padding. Now, UIStackView
makes all that a snap. Or if Auto Layout seemed too verbose, a new compact API provides a more readable way to create constraints. Previously, Apple provided a few layout guides to ease certain layouts, and now you can create your own. Layout guides also provide great replacements to tricks like spacer views.
With API improvement, it’s now easier to target an international audience. With comprehensive support for layout mirroring, it’s straightforward to support right-to-left languages. Improved testing allows you to stress-test layouts without reading that language. Extended formatters make it easier to describe numbers, dates and now even names, all without having to write exceptions for or understand the rules in every language, culture and region in which your users can be found. With a little investment on your part, the new APIs can meet you halfway to embrace proper localization for your app.
Even web developers are getting new accommodations on Apple’s platforms this year. CloudKit gets an API for access from web apps. Better support for web apps makes it easier to use them on the Mac day-to-day. Deep linking makes it easier to go from the web to a specific part of your app, or vice versa, and the OS can even index the content of your sites and apps.
Apple promises this year’s OS X and iOS will make users’ devices work more efficiently in more situations, and developers are being brought along for the ride. Through tools that build on last year’s Handoff, an application can give the device contextual awareness of what it can do, enabling powerful integration with Siri, Reminders and other apps, all automatically. With a little more work, your app can even opt into robust system-wide search using CoreSpotlight.
iOS and OS X getting smarter doesn’t stop at the user-facing features. HealthKit, HomeKit and CarPlay gain new points for extension and automation. The developer tools have also grown a lot of smarts. Energy-saving tools mean that your apps will have less of an impact on a user’s battery. Improved debugging with Address Sanitized lets you catch intractable memory errors that cause crashes for your users. GameplayKit even provides a simple interface for complex AI and decision-making.
Speaking of games, this year highlights an ongoing emphasis on gaming technologies and high-performance applications. With Metal on the Mac, games and data-heavy applications are run more efficiently. Metal shaders allow offloading boost high-performance processing by offloading complex math to a device’s GPU, while other built-in shaders make visually stunning games easier to build—all tuned performance for every supported device.
Xcode receives enhanced tools for building better software. UI testing lets you exercise user scenarios automatically and look at performance over time. Code coverage can measure the thoroughness of your test code, improving quality as you uncover edge cases and regressions over time. And with a unified Developer Program, Apple ID-based provisioning and Free Provisioning, getting into these platforms is easier than ever before.
Swift, Apple’s next generation programming language introduced to a shocked audience just a year ago, was nothing if not polarizing. But both Objective-C stalwarts and those bullish on Swift could agree on one thing: Swift needed a little more time to bake. We got a taste of what was to come back in January with Swift 1.2, but 2.0 Swift delivers on many of the promises made last year.
With a new error-handling mechanism and the ability to conditionally run code across device versions, Swift code eliminates boilerplate to become even safer. New syntax, like guard
statements and protocol extensions, encourage writing more compact and reusable code without losing readability. Many special rules, such as the different ways functions could be called, have even been removed to make writing Swift more consistent. Most of these changes are supported by Xcode’s conversion tools, simplifying updating existing code to run under the new syntax.
Objective-C has been improved to better coexist with Swift. Apple have annotated all their frameworks to add type information to collections like NSArray
and when nil
use is accepted. Not only does this make it dramatically easier to interact with Objective-C from Swift, but Objective-C gets better warnings to improve working with older code.
In a dramatic flourish, Apple also announced that Swift will see an open source release this fall. The crowd of developers, and the wider community, exploded with excitement and speculation about what this announcement means for Swift and Apple. While it may not change how you interact with the language day to day, or how you build iOS apps right now, it allows for a much larger community of Swift developers. The move also promises a bright future for the language beyond the scope of Apple’s devices.
You don’t have to be introducing flashy new features to be moving at a breakneck speed. In fact, the announcements at WWDC show a commitment to everything that’s come before while still pushing forward. The launches of iOS 8 and OS X Yosemite may have been bumpy, but they laid the groundwork for what we see today. In refining the features and developer tools for iOS, OS X and the fledgling watchOS, all three platforms are going to be stronger for building a product or business on.
The work of building your apps is changing. Your days, Apple suggests, should be less filled with fighting pixel-for-pixel layout or figuring out how to handle errors writing repetitive and buggy code. They should be spent on stronger engineering. They should be spent on building applications that are smarter, faster and more resilient. They should be spent on figuring out how to make your apps easier to use by people around the world. Apple’s attempt is to take away those concerns by building a stronger platform. By getting on board with the latest advancements—which is not always easy—you can spend less time on the mundane and more time on the meaningful.
Our introductory guide to Swift Regex. Learn regular expressions in Swift including RegexBuilder examples and strongly-typed captures.
The Combine framework in Swift is a powerful declarative API for the asynchronous processing of values over time. It takes full advantage of Swift...
SwiftUI has changed a great many things about how developers create applications for iOS, and not just in the way we lay out our...