Originally Posted on XCBlog here
Apple’s World Wide Developer Conference (WWDC) 2018 has been started this week. As promised, I will be writing series of blog posts on the WWDC contents as it’s being announced. There were lots of announcements about newsoftware like iOS12, watchOS5 etc. However, there was another session Platforms State of the Union which is kind of keynote for the developers working on the 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 the Xcode yet.
Xcode 10 has many features that have been announced at Platforms State of the Union session at WWDC. We will only cover following features as part of this post.
- Parallel Testing: XCTest and XCUITest
- Code Snippets
- Scheme Editor
- Multiline Editing
- New Build System
- Source Control
We will briefly look into those features of Xcode.
Parallel Testing: XCTest and XCUITest
Apple actually announced the parallel testing feature last year WWDC17, where we can specify multiple destinations and tests will trigger on different simulators or devices accordingly. You can read more about the XCTest feature announced last year here. However, this year it gets extended to parallelizing test suites within single simulator by creating clones of the simulators. Xcode creates different runner process under the hood and each process gets specific tests assigned. This reduces the test execution dramatically.
We can enable the parallel testing by updating the scheme and in the Test action, we can select “Options” against test bundle to choose parallelization option. We can select location as well.
There are a couple other option to randomize the tests and 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 the parallel for that scheme.
By default, there is only two runner process assigned but we can increase the number when running from command line. In the Xcode test reports which simulator clone runs which tests. The test reports are grouped together.
This is actually great improvements in the 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 various option to run XCTest in parallel has been added to the xcodebuild tools which we will explore in the below section of the article.
Xcode 10 has been 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 the xcodebuild for various purpose.
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 the
- -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 the XCTests in the parallel as we have done it 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 the 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 correct membership details to connect to Apple developer portal.
Apple has introduced another service called notarized app which means Apple will stamp the app before uploading 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 a command line as well.
$ xcodebuild -exportNotarizedApp -archivePath <xcarchivepath> -exportPath <destinationpath>
We can also use an option -exportNotarizedApp to export an app that has completed Developer ID notarization.
With Xcode 10, we can create custom code snippets and reuse whenever needed. This is the cool feature and accessible from Xcode Editor menu — -> Create Code Snippet
The power of snippets comes in when we can create snippets in Swift and specific platform but the real power comes in when we can also able to create snippets for other languages as well. e.g Ruby, YAML etc. We have to define the shortcut keys for the snippets. On top of this, we have access to default Swift templates to create the snippet. e.g 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 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 have an ability to filter the schemes by typing something as soon as we press CTRL+0 key.
We can use the similar technique to use select target device/simulator by pressing CTRL+SHIFT+0 key.
Xcode 10 supports multi-line editing by selecting multiple instances by holding CTRL+SHIFT and selecting the spots. e.g we want to change all functions to private functions, then we can select all instances of func and replace it with private function 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 has been 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 previousblog post.
Source Control Enhancements
Last year Apple has 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 that, developers can take actions like discard changes, pull changes, rebase change straight from Xcode.
Source Code Available on Github: Xcode10-Demo
Missing Parts in Xcode
Although Xcode 10 has announced some great features, there is still something missing
- There is nothing related to Continuous Integration in Xcode e.g BuddyBuild Or Xcode Server as of now. There is 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 those were announced at the WWDC 2018. As we progress through the WWDC session, we will cover the details of each topic in the later blog posts. Hope you like Xcode 10 features those are announced in the WWDC, What is your opinion on those? Do you think anything missing there that you have expected?
Like this post from XCBlog By XCTEQ ? You may also like some of our services like guest blogging or Mobile DevOps(CI/CD) or Test Automation. Chekout our services, open source projects on Github or Follow us on Twitter , Facebook, Youtube , LinkedIn. Download Our XCBlog iOS App to read the blogs offline.