English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Xcode 8Usage of New Features and the Pits Encountered

Currently still using Xcode 7.3 There has been no update for a long time, as poor me had made so many plugins... Back to the topic, I have been using Xcode 8has been paying attention to since its launch, and today I happened to see an article summarizing it well, so I转载过来 and also organized it again. Thanks to the original author!

The original text is as follows:

Xcode 8the official version is9month13has been pushed to developers for download, and after returning from the National Day holiday, I also downloaded the new Xcode. After downloading, many compilation errors appeared, and the previous plugins could not be used either, but I found that Xcode8has integrated many good plugin functions into itself, and I feel that this point is also very good.

Each version of Xcode brings many new features, Xcode 8As for them, these new features will bring convenience to our development and also many pitfalls. So today I plan to write an article to discuss Xcode in detail.8new features and pitfalls it brings, as well as some problems I encountered during use, I hope it can help other friends.

Xcode8 new feature

Interface Builder

With the14year's iPhone6and6After the release of iPhone

In iPhone6and6The same year as the release of Apple's Xcode6In addition to the original Auto Layout, Apple has added the new feature of Size Classes, which allows you to use a single XIB or SB file to adapt to different screens and both iPhone and iPad devices.

In Xcode8Apple has launched a more powerful visual editing tool preview feature, which can preview the current XIB or SB under different screen sizes without running the App. (I remember that this feature was in Xcode before, but it was hidden very deeply, and Apple has brought it out now)
Select an XIB file and click on the position in the red box below. It will appear from3.5A-5.5A series of screen size options. Click on different screen sizes and landscape/portrait options to switch to different screen displays. On the iPad, you can also choose whether to split the screen, which is very powerful.

 

Interface Builder

There is a Vary for Traits option on the right. Clicking this option can display all available screen styles at the same time, and the functions are the same as those in the picture above, just that the display looks more extensive.

 

Interface Builder

There is also one point, the size of the new XIB control is no longer600*6It is not the square of 00, but it is default6The rectangular XIB file looks much more comfortable.

Changes in General of Target

In Xcode8Before that, you had to set up the certificate and description file yourself. If there is an error in the settings, you can also fix this error by clicking Fix issue. However, there is a problem with the Fix issue option, it is not very useful, and sometimes the settings are correct but it still prompts for Fix issue.

Apple may also be aware of this issue, in Xcode8Through the Automatically manage signing option, Apple can manage the certificates and configuration files for us, and all the settings are completed by Apple. In Xcode8In the new project, this option is checked by default.

 

Automatically manage signing

From the above figure, you can see that Apple automatically manages the certificates and configuration files for us. Moreover, in previous projects, if you wanted to set the App name displayed on the phone after installation, you needed to modify the Display Name field in the Info.plist file yourself. Now, you can make this change directly in General, and it is synchronized with Info.plist.

But, if I want to manage the certificate and description file myself? Just remove the Automatically manage signing option.

Automatically manage signing

If you manually set the certificate and description file in the Build Settings, you will find that the Provisioning Profile option is marked as Deprecated, which means that Apple does not recommend manual settings.

Xcode plugins

Upgrade Xcode8after that, you will find that in Xcode8all third-party plugins have become ineffective, and even the plugin options in the previous menu bar have disappeared. In the past, many iOS developers used Alcatraz to manage plugins, but now Alcatraz is also unavailable. However, Xcode8has also upgraded the compiler, adding some good plugin features to Xcode, such as line highlighting.

In Xcode8supports the development of plugin projects and provides us with a plugin template. The plugins developed can be uploaded to the App Store for download. Apple does this for a reason: previously, Xcode and plugins ran in the same process, so plugin crashes could also cause Xcode to crash. Now, Apple runs plugins as a separate application, running in a separate process, which will not affect Xcode.

 

Xcode Source Editor Extension

Runtime Issues

During the development process, because of syntax or obvious code errors (such as Retain Cycle), the compiler can find and report yellow or red warnings. However, some errors caused by code logic cannot be found by the compiler. For example, the following line of code, because of the problem with the code logic, causes two arrays to reference each other and neither can be released.

 

Array circular reference

At this time, you can use Xcode8The new feature of Runtime Issues provided, finds issues that occur during runtime and visualizes the problems to developers in the form of a graph.

 

Runtime Issues

Debug Memory Graph

In Xcode6The new feature of Debug View Hierarchy has appeared, which can be used to debug the view hierarchy of the current App and it is very convenient to find UI-related bugs. In Xcode8Apple provides the Debug Memory Graph feature to developers, which allows you to directly select an object and view the memory relationships associated with it.

 

Debug Memory Graph

Debug Memory Graph and Runtime Issues can be used together. After analyzing memory relationships with Debug Memory Graph, clicking on Runtime Issues will show the memory issues that have been found.

Swift 3

Xcode8Swift3has brought a new version of Swift8The new version of Swift has changed significantly. If the old version of Swift project is in Xcode

compilation may fail. In response, Apple has provided a Swift migration tool for developers, which is said to be not very good (I haven't used this tool).3If you do not want to migrate to Swift2.3You can set it in Builder Settings, select Use Legacy Swift Language Version and set it to YES to continue using the old version of Swift

 

.

Use Legacy Swift Language Version

Other updates

Xcode new version font, SF Mono Regular font. After updating Xcode, I prefer this font, which looks very neat.8The highlight function has been integrated, making it very convenient to use. The edited line is highlighted. There was a plugin for this feature in the previous Xcode

The latest version of the API document has changed greatly in style.

Generate documents more conveniently (which is written by the cat god VVDocumenter), in Xcode8You can place the cursor on the method and use option + command + /Generate document comments with shortcut keys.

Xcode 8Adaptation

XIB and Storeboard Adaptation

In Xcode8Before creating an XIB or SB file, it is a600*600 block XIB file. In Xcode8After that, the XIB file created by default is6s size.

However, Xcode8When opening the XIB or SB file of an old project, the following dialog box will pop up. At this time, it is generally recommended to directly select Choose Device.

 

Choose an initial device view

However, there is a problem with this, if Xcode8After opening this XIB file and selecting Choose Device.8The following versions of compilers will no longer be able to open this file, and the following error will be reported:

The document “ViewController.xib” requires Xcode 8.0 or later. This version does not support documents saved in the Xcode 8 format. Open this document with Xcode 8.0 or later.

There are two ways to solve this problem:

You should also upgrade Xcode8This method is recommended, and we should embrace change.

Right-click on the XIB or SB file -> Open as -> Source Code, delete the following field in the xml file.

Compilation errors

After upgrading Xcode, Xcode8Incompatibility with some modifiers and statements from before may cause some compilation errors. The reasons for these errors are many, so here are several general ones, and everyone should still make modifications according to their own situations.

Before some generic-related modifiers, such as nullable, some may report errors.

CAAnimation and its subclasses, after setting the delegate property, you must comply with the delegate at @interface(), otherwise an error will occur, etc.

Permission compatibility

This should be considered as iOS10System compatibility scope, recently both of these have been working on, so they were directly written with Xcode8Compatibility has been written together.

In iOS10After that, you need to add new fields to Info.plist to obtain permissions, otherwise you will not be able to use push notifications on iOS10Running on the device will cause a crash. Below are some common fields, if there are any missing

Too few, please supplement in the comment area.

Reference materials: developer.apple

Push Notifications

Apple's push in the previous iOS8and iOS9There was a major update, and the push feature became more powerful. In iOS10After that, Apple launched the UserNotifications framework, which can better control push notifications through this framework, can update and modify the push messages on the lock screen page, can add images and other functions.

But when using Xcode8After packaging and not modifying the code, I found that Apple sent an email. The email basically means that if you need to use push notifications, you need to modify the code, otherwise you will not be able to use push notifications.

 

Push Notifications

This is because in Xcode8After that, if you need to use the Push Notifications feature, you need to check the Capabilities -> Push Notifications should be YES, otherwise there will be problems with remote push, and you will receive this email from Apple.

Delete system logs

Upgrade Xcode8After that, during the debugging and running process, I found that the console printed a lot of unrecognized logs, which are system logs and have nothing to do with developers. However,

So many logs look a bit messy, how can I screen them out?

subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0

In Target -Edit Scheme -Run -Add the OS_ACTIVITY_MODE field in Arguments and set it to Disable.

 

OS_ACTIVITY_MODE

By the way, when setting the log options these days, I found that you can print out the loading time of the App by setting parameters in Arguments, including the overall loading time, dynamic library loading time, etc. 

Add the DYLD_PRINT_STATISTICS field in Environment Variables and set it to YES, and the loading time will be printed in the console.

Console print information

awakeFromNib warnings

Old projects in Xcode8In some places where the awakeFromNib method is overridden, the following error will be reported. This is because the super method was not called, fortunately, I always call super, and the code is currently not problematic.

Method possibly missing a [super awakeFromNib] call

The above is what the editor introduced to everyone about Xcode 8Use of new features and pitfalls encountered, hoping to be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to everyone in time. Also, I would like to express my sincere gratitude to everyone for supporting the Yell Tutorial website!

Declaration: The content of this article is from the Internet, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, does not edit the content manually, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to notice#w3Please report any violations by email to codebox.com (replace # with @) and provide relevant evidence. Once verified, the website will immediately delete the infringing content.

You May Also Like