WWDC18: Xcode 10 in Action
WWDC18: Xcode 10 in Action
See what's happening at Apple's World Wide Developer Conference, with many new Xcode 10 features being announced.
Join the DZone community and get the full member experience.Join For Free
Apple's World Wide Developer Conference (WWDC) 2018 started this week. As promised, I will be writing a series of blog posts on the WWDC contents as they are announced. There were lots of announcements about new software like iOS12, watchOS5, etc. However, there was another session, Platforms State of the Union, which is kind of a keynote for developers working on Apple platforms. Apple Announced Xcode 10 with loads of new features and most of them were demonstrated in the session. In this post, we will quickly explore the new features of Xcode 10 using the macOS high Sierra as macOS Mojave isn't public so we won't see the dark mode of Xcode yet.
Xcode 10 has many features that have been announced at Platforms State of the Union session at WWDC. We will only cover the following features as part of this post:
- Parallel Testing: XCTest and XCUITest
- Code Snippets
- Scheme Editor
- Multiline Editing
- New Build System
- Source Control
Parallel Testing: XCTest and XCUITest
Apple actually announced the parallel testing feature last year at WWDC17; we can specify multiple destinations and tests will trigger on different simulators or devices accordingly. However, this year it gets extended to parallelizing test suites within a single simulator by creating clones of the simulators. Xcode creates different runner processes under the hood and each process gets specific tests assigned. This reduces the test execution dramatically.
We can enable parallel testing by updating the scheme and in the Test action, we can select “Options” against the test bundle to choose the parallelization option. We can select location as well.
There are a couple other options to randomize the tests and the ability to add new tests in the scheme. Let’s focus on parallelization first. Once the checkbox is checked, we are all set to execute tests in parallel for that scheme.
By default, there are only two runner processes assigned, but we can increase the number when running from the command line. In Xcode, tests report which simulator clone runs which tests. The test reports are grouped together.
This is actually a great improvement in test execution speed. We can speed up unit tests as well as UI tests drastically using the parallel testing technique. We should be still able to execute tests with multiple simulator destinations using this technique.
The option to run XCTest in parallel has been added to the xcodebuild tools, which we will explore below.
Xcode 10 shipped with various command line tools that can help to achieve various things from the command line or scripts. Here are some new options added to xcodebuild for various purposes.
It’s possible to run the XCTest from the command line using the xcodebuild tool. With Xcode 10, we have few more options to enable parallel testing those are
- -maximum-concurrent-test-device-destinations NUMBER : the maximum number of device destinations to test on concurrently
- -maximum-concurrent-test-simulator-destinations NUMBER : the maximum number of simulator destinations to test on concurrently
- -parallel-testing-enabled YES|NO : overrides the per-target setting in the scheme
- -parallel-testing-worker-count NUMBER : the exact number of test runners that will be spawned during parallel testing
- -maximum-parallel-testing-workers NUMBER : the maximum number of test runners that will be spawned during parallel testing
These options allow us to execute XCTests in the parallel as we have done from Xcode 10. We have a project and scheme that configured for the parallel testing, then we can easily execute the following command to achieve parallel testing in the iPhone X simulator.
$ xcodebuild -project Xcode10-Demo.xcodeproj/ -scheme Xcode10-Demo -destination 'platform=iOS Simulator,OS=12.0,name=iPhone X' clean build test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -parallel-testing-worker-count 4
This command will start the execution of the four clones of the iPhone X simulator.
We can achieve the same results from the command line for parallel testing.
Upload App to App Store
It’s possible to upload an iOS app to App Store from the xcodebuild tool with Xcode 10 release with the following command:
$ xcodebuild -exportArchive -archivePath <xcarchivepath> [-exportPath <destinationpath>] -exportOptionsPlist <plistpath>
We need to pass the ExportOptions.plist file containing the key destination and value upload; also, we have to make sure that Xcode is configured with the correct membership details to connect to the Apple developer portal.
Apple has introduced another service called "notarized app," which means Apple will stamp the app before uploading it to App Store. We have to upload an app to be notarized by Apple. There is an option in xcodebuild now to perform this action from the command line, as well.
$ xcodebuild -exportNotarizedApp -archivePath <xcarchivepath> -exportPath <destinationpath>
We can also use the option -exportNotarizedApp to export an app that has completed Developer ID notarization.
With Xcode 10, we can create custom code snippets and reuse them whenever needed. This is a cool feature and is accessible from Xcode Editor menu--->Create Code Snippet.
The power of snippets comes in when we can create snippets in Swift and specific platforms, but the real power comes in when we can also create snippets for other languages as well, e.g. Ruby, YAML, etc. We have to define shortcut keys for the snippets. On top of this, we have access to default Swift templates to create the snippet; we will create a snippet for the XCTActivity so that we don’t need to repeat that closure every time we implement steps. We will add some code snippet that will be invoked when we press $9 in the Xcode. Now every-time, you press $9 in Xcode, it will prompt you a snippet that you have already created.
Once you have selected the code snippet, this will enter the whole snippet that we set up.
With Xcode 10, it’s even handy to select and edit schemes and devices. With the simple CTRL+0 keystroke, Xcode will highlight the schemes section and we can navigate through the existing schemes. We can also filter the schemes by typing something as soon as we press CTRL+0.
We can use a similar technique to use select the target device/simulator by pressing CTRL+SHIFT+0.
Xcode 10 supports multi-line editing by selecting multiple instances by holding CTRL+SHIFT and selecting the spots. If we want to change all functions to private functions, then we can select all instances of func and replace them with private functions, as shown below.
It can also be applied to the column editing as well as mentioned shown in WWDC demo.
New Build System
The new build system was announced last year but was not activated in Xcode 9 by default. However, in Xcode 10, the new build system has been activated by default. We can still go back to the old, legacy build system from Xcode-Files-Project/Workspace settings options. You can read more about the new build system in one of the previous blog posts.
Source Control Enhancements
Last year, Apple announced tight integration with GitHub (you can read more about it here). This year, Apple integrated more source control systems like GitLab and BitBucket. More importantly, Xcode can now highlight that changes from Xcode developers will be able to resolve merge conflicts from Xcode itself. Another great feature is users can create ssh keys from Xcode and upload to the remote source control.
As you can see, developers can take actions like discard changes, pull changes, or rebase changes straight from Xcode.
Source code available on GitHub: Xcode10-Demo
Missing Parts in Xcode
Although Xcode 10 announced some great features, there is still something missing:
- There is nothing related to Continuous Integration in Xcode, like BuddyBuild or Xcode Server as of now. There are a couple of sessions still to come, but as of now, there isn’t anything related to CI.
- Anything else you can think of, waive in the comments.
We have just seen few high-level features of Xcode 10 in action, which were announced at WWDC 2018. As we progress through the WWDC sessions, we will cover the details of each topic in later blog posts. I hope you like Xcode 10 features that are announced at WWDC. What is your opinion on those? Do you think anything missing there that you expected?
Published at DZone with permission of Shashikant Jagtap , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.