Xcode 8 The use of new features and encounters with pits _ios

Source: Internet
Author: User
Tags comments documentation modifiers system log

is still using Xcode 7.3 has not been updated, after all, poor I made so many plug-ins ... Back to the point, from the Xcode 8 has been in the spotlight, today happened to see an article summed up the good, conveniently reproduced over and over again, thanks to the original author!

The original text reads as follows:

The official version of Xcode 8 was pushed to the developer's download on September 13, and I downloaded the new Xcode after 11 back. After downloading a lot of compiler errors, the previous plug-ins can not be used, but found Xcode8 a lot of good plug-ins to integrate the function of their own, it is very good feeling this.

Each version of Xcode will bring a lot of new features, Xcode 8 is no exception, these new features will bring convenience to our development, will also bring a lot of pits. So today I'm going to write an article detailing the new features that Xcode8 brings to us and the pits it brings, as well as some of the problems I encountered during my use, hoping to help other friends.

Xcode8 new Features

Interface Builder

With the advent of the 14 iPhone6 and 6P, the iphone's screen size has become more and more, and the screen fitting is a problem that needs to be solved, and not necessarily what size the iphone will be.

In the same year that IPhone6 and 6P were released, Apple introduced a new feature of size classes, based on the original auto layout, that could use a xib or SB file in Xcode6. Fit different screens and two devices for the iphone and ipad.

In Xcode8, Apple has a more powerful visual editing Tool preview feature that lets you preview the display of current xib or SB under different screen sizes without running the app. (This function I remember before Xcode have, just hidden deep, the apple is now to get outside)
Select a xib file to go in, click on the red box below the position, will appear from 3.5-inch-5.5-inch series of screen size options. Click on a different screen size, as well as the horizontal screen options, switch different screen display. On the ipad can also choose whether to split the screen, the function is very powerful.

Interface Builder

On the right there is a vary for traits option, click this option to display all of the optional screen styles at the same time, with the same features as the pictures above, but the display looks more.

Interface Builder

Also, the newly created Xib control size is no longer the square of the previous 600*600, but the default is a 6s rectangular xib file that looks much more comfortable.

The general change in target

Before Xcode8, you need to set up your own certificate and description file. If the settings are incorrect, you can also fix the error by clicking Fix Issue. The problem with this is that the fix issue option is not as good as it is, and sometimes the settings are correct and you need to fix issue.

Maybe Apple is also aware of the problem, and in Xcode8 we can use the Automatically manage signing option to let Apple manage the certificates and configuration files for us, and the settings are also made by Apple. To create a new item in Xcode8, this option is checked by default.

Automatically manage signing

As you can see from the image above, Apple has helped us automate the management of certificates and profiles. And in the previous project, if you want to set the name of the app that is displayed on your phone after you install it, you'll need to go to the Info.plist file, modify the Display Name field, and now you can make the changes directly in general, which is synchronized with the info.plist.

But what if I want to manage my own certificate and description file? Just remove the Automatically manage signing option.

Automatically manage signing

If you manually set up certificates and profiles in build settings, you may find that the provisioning Profile option has been marked as deprecated, which is that Apple does not recommend manual setup.

Xcode Plugin

After you upgrade Xcode8, you will find that all Third-party plug-ins in Xcode8 are invalid, and the plugin options for the previous menu bar do not exist. In the past, many iOS developers, are through the Alcatraz to manage Plug-ins, and now Alcatraz is not available. But Xcode8 itself has also upgraded the compiler, adding some of the better plug-in features to the Xcode, such as a single line highlighting.

In Xcode8 support the development of plug-in engineering, and provides us with a plug-in template, the development of Plug-ins can be uploaded to the App Store download. One reason Apple does this is that before Xcode and Plug-ins are running in the same process, the collapse of the plugin can also cause Xcode to crash. Apple now takes the plug-in as a separate application that runs separately and does not have any other impact on Xcode.

Xcode Source Editor Extension

Runtime Issues

During the development process, the compiler can discover and report a yellow or red warning because of syntax or obvious code errors (such as retain Cycle). But some errors caused by the logic of the code, the compiler is not able to find. For example, the following code, because the problem of code logic causes two arrays to reference each other, can not be released.

Array Circular Reference

At this time, we can find the problems in the running process through the runtime issues provided by Xcode8, and visualize the problem to the developer through graph.

Runtime Issues

Debug Memory Graph

A new feature of the Debug view hierarchy appears in Xcode6, and it is convenient to find UI-related bugs by debugging the view level of the current app. In Xcode8, Apple provides developers with the debug Memory graph feature, which allows you to directly select an object to view its associated memory relationship.

Debug Memory Graph

Debug Memory graph and runtime issues can be used together, after the debug Memory graph analysis of the memory relationship is complete, click on runtime issues to see the memory problem that has been discovered.

Swift 3

Xcode8 has brought a new version of Swift3, and the new version of Swift has changed a lot, and if the older Swift project compiles on Xcode8, it may fail. In this respect, Apple has provided a swift migration tool for developers, and has heard that it is not very useful (I have not used this tool).

If you do not want to migrate to Swift3 immediately, you can set it in builder settings and choose Use Legacy Swift Language version to be set to Yes to continue using the old version of Swift2.3.

Use Legacy Swift Language Version

Other updates

Xcode new Font, SF Mono regular font. After updating Xcode I like this font, it looks very neat code.

The edited row is highlighted. Before Xcode has a plug-in is this function, Xcode8 the highlight function integrated in, easy to use.

The latest version of the API documentation, the presentation style has changed a lot.

More convenient to generate documents (that is, the Vvdocumenter), in the Xcode8 can place the cursor on the method, the OPTION + COMMAND +/shortcut key to generate documentation comments.

Xcode 8 Fitting

Xib and Storeboard adaptation

Before Xcode8, create a xib or SB file, which is a 600*600 box Xib file. After Xcode8, the Xib file created by default is the size of 6s dimensions.

But Xcode8 open the old item before the Xib or SB file, will pop up the bottom of the frame, this time the General direct choice choose device can.

Choose an initial device view

But there is a problem, if Xcode8 open the Xib file and select Choose Device. Other Xcode8 versions of the compiler will no longer be able to open the file and report the following error:

The document "Viewcontroller.xib" requires Xcode 8.0 or later. This version does is not support documents saved in the Xcode 8 format. The Open this document with Xcode 8.0 or later.

There are two ways to solve this problem:

You also upgrade Xcode8, and recommend this approach, should meet the change.

Right-click the xib or SB file-> Open as-> Source Code to delete the following line of fields in the XML file.

Compile error

After you upgrade Xcode, Xcode8 is incompatible with some of the previous modifiers and statements, resulting in some compilation errors. This kind of mistake causes many reasons, here roughly a few, everybody still according to the situation that oneself encounters make changes.

Some generic-related modifiers, such as nullable, can be an error.

Caanimation and its subclasses, set agent properties, must be in @interface () comply with the agent, or error, and so on.

Right fit

This should be the category of IOS10 system adaptation, these two are in the past, so directly and Xcode8 fit together to write out.

After iOS10, you need to add a new field in Info.plist to get permissions, otherwise running on the iOS10 can cause crashes. Here are some common fields, if there are missing

Less trouble. Please add to the comments section.

References: Developer.apple

Push notification

Apple's push in the IOS8 and iOS9 before the big update, push function is more and more powerful. After iOS10 Apple launched the Usernotifications framework, through this framework to better control the push notification, you can update, modify the lock screen page push message, you can add pictures and other functions.

However, after packing with Xcode8, and without modifying the code, it is found that an e-mail message was sent to the Apple after it was packaged. This email probably means that if you need to use push notifications, you need to make changes to the code, otherwise you won't be able to use push notifications.

Push Notifications

This is because after Xcode8, if you need to use the Push notifications function, you need to check the capabilities-> push Notifications is yes, otherwise there will be a problem with remote push, And will receive this email from Apple.

Delete System Log

After upgrading the Xcode8, in the debugging and running process, found that the console print a lot of the log is not known, the log is the system printing, and developers do not mind. But

So many log look more messy, how to shield off?

Subsystem:com.apple.UIKit, category:hideventfiltered, enable_level:0, persist_level:0, default_ttl:0, info_ttl:0, de bug_ttl:0, generate_symptoms:0, Enable_oversize:1, Privacy_setting:2, enable_private_data:0

In target-> Edit Scheme-> Run-> arguments, add the Os_activity_mode field and set it to disable.

Os_activity_mode

By the way, these two days when the log option is set, it is found that you can print out the length of the app load by setting the parameters in the arguments, including the overall load time, dynamic library load time, and so on.

Add the Dyld_print_statistics field in the environment variables and set to Yes, and the length of the load is printed on the console.

Console printing Information

Awakefromnib Police report

The old project in Xcode8, some rewrite the awakefromnib method Place, will report the following error. This is because there is no call to super method caused, fortunately I usually call Super, the code is not a problem.

Method possibly missing a [super awakefromnib] Call

The above is a small set to introduce the Xcode 8 new characteristics of the use and encounter the pit, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.