IOS 11 Series-Xcode 9 new features

Source: Internet
Author: User

Xcode 9 has just recently been released, bringing a number of new features that will help developers get the job done.

Xcode Runtime Tool

There are many runtime tool in Xcode 9 that can help developers find code errors, including the following:

    • Main Thread Checker-xcode 9 New introduction

    • Address Sanitizer

    • Thread Sanitizer

    • Undefined Behavior Sanitizer

    • Using Runtime Tools effectively

Main Thread Checker

Main Thread Checker can help developers find UI actions that are not performed in the main thread.

Settings can be found in the diagnostics panel, and Xcode is checked by default:

At run time, if any of the main thread problems are found, you will be prompted as follows:

Address Sanitizer

Address sanitizer can be used to detect memory problems, the address sanitizer Open will bring a relatively large overhead, so developers need to manually set.

Once turned on, any memory issues are detected and prompted automatically, as shown in:

1. You will be prompted to tell which line of code has used the freed memory object

2. The left panel will tell you the exact creation, use, and release of the object, which is very convenient to debug

Thread Sanitizer

For discovering multi-threaded issues, the thread sanitizer in Xcode 9 can help:

1. Discovery of data race issues in multi-threading

2. The data race in the collection

3. Swift Access Races

As shown in Swift's data multi-threaded race on array:

You can solve this by introducing a queue to synchronize multiple threads:

Common ways to solve multi-threaded data race problems:

1. Synchronizing Data operations with GCD

2. Using serial queue to serialize the operation of shared data

3. Thred sanitizer is a great tool for finding data races

Undefined Behaviour Sanitizer

As the name implies, Undefined behaviour Sanitizer can help developers find some anomalies at runtime, including the following:

1. Run-time bug lookup: integer overflow,

2. Check for unsafe constructs in C

3. And other run-time tools are compatible

Using Runtime Tools effectively

Apple offers some suggestions for the runtime tool in Xcode 9

1. Use continuous integration to discover run-time errors during testing

2. Address sanitizer and thread sanitizer are not compatible, so they cannot be used simultaneously

The runtime tool has some overhead, as follows:

Resources:

Finding Bugs Using Xcode Runtime Tools

Clang documentation for Address sanitizer

Clang documentation for Thread sanitizer

Clang documentation for Undefined Behavior sanitizer

Code Diagnostics

Undefined Behavior Sanitizer

Debugging with Xcode 9

Support the wireless debug, can no longer need to connect the data cable for the real machine development work

Enhanced breakpoints: Conditional breakpoints are supported and additional statements can be executed at breakpoints

Viewcontroller Debugging: You can view the Viewcontroller information when viewing the view hierarchy

Resources:

Debugging with Xcode 9

Localizing with Xcode 9String Management

Use nslocalizedstring to load multiple languages and use Localizedstringwithformat to load formatted multiple languages.

//Set A label ' s textLabel.text ="Population"//Set A label ' s text to a localized stringLabel.text = nslocalizedstring ("Population", Comment:"Label preceding the population value")//Load localized string from a specific tableLabel.text= Nslocalizedstring ("Population", Tablename:nil, Comment:"Label preceding the population value"//Create a formatted string    "Localizable", Bundle:. Main, Value:) Letformat= Nslocalizedstring ("%d Popular languages", Comment:"Number of popular languages") Label.text= String.localizedstringwithformat (format, Popularlanguages.count)

Use static analysis to help find text that is not localized, tick the missing localizability and missing Localization context Comment in build setting.

Static resources are organized in the project as follows:

Base.lproj: Base Resource Pack

En.lproj: Text Resources in English

Stringsdict

You can use different localized strings depending on the scenario, such as the case of a single complex number:

Adaptive Strings

Different localized strings can be displayed according to specific criteria, such as displaying different text under different screen sizes

String resource can support import and export in Xliff format

Resources:

Localizing with Xcode 9

What's New in testing Async testing

You can use it for asynchronous behavior testing by setting the desired condition and then waiting for validation. Introduce Xctwaiter to specify the expectations of asynchronous behavior in a way that is displayed.

//Test Case Waits implicitly
Waitforexpectations (timeout:Ten)//Test case waits explicitlyWait for: [Documentexpectation], timeout:Ten)//Waiter instance delegates to testXctwaiter (Delegate: self). Wait ( for: [Documentexpectation], timeout:Ten)//Waiter class returns resultLet result = xctwaiter.wait ( for: [Documentexpectation], timeout:Ten) ifresult = =. timedout {//handling the timeout ...}
Multi-app

Supports simultaneous automated testing of multiple apps, often for: app Groups,extensions

UI Testing Performance

Xcode 9 provides a number of optimizations for UI testing that improve performance

Resources:

What ' s New in testing

IOS 11 Series-Xcode 9 new features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.