This profile

  • This topic: Some introduction to In-App Events.
  • Tips: A few Tips for optimizing incremental compilation in Xcode.
  • Interview module: a RunLoop related question.
  • Good blog: This blog is about Swift’s high-level intermediate language: SIL.
  • Learning materials: raywenderlich’s new Flutter tutorial; A handbook of cognitive bias.
  • Development tool: a terminal command completion tool: FIG.

This topic

The content of this interview is a little late, pause the first, next time will be 😅.

Apple’s official website often updates some activities or development related information, we plan to do some sorting and screening regularly to help you understand the relevant information.

In-app Events

iHTCboy

In-app events are time-sensitive events within the App and the game, such as game contests, movie premieres and live streaming experiences. Users can explore your in-app activities directly in the App Store on iOS and iPadOS. Whether you want to attract new users, update current users, or reconnect with previous users, this feature can help you present your campaign in a new way and expand its reach.

Apple opened its background on Oct. 22 to upload campaign material for review. It is important to note that this feature is currently in beta and requires developers to accept this agreement.

From October 27, 2021, users will be able to see in-app activity on the App Store for devices with iOS 15 or higher.

In detail, see: developer.apple.com/cn/app-stor…

The development of Tips

Xcode incremental compilation optimization

zhangferry

Incremental compilation is the most commonly used scenario for development, as opposed to full compilation, so the benefits of improvements in this area are often more substantial. Using the Apple documentation Improving the Speed of Incremental Builds, we can optimize Incremental Builds in a number of ways.

Before starting optimization, it is more important to measure the compile time. Only by measuring the index can we accurately analyze the optimization effect. Time can be measured by Xcode’s Product > Perform Action > Build With Timing Summary, and then at the bottom of the Build log you can view the time statistics for each stage.

The following are the optimization suggestions:

Declare Inputs and Outputs for scripts and build rules in the script build phase

Each time a script in Build Phase is prepared for execution, it is determined by its inputs and outputs. Scripts are executed in the following cases:

  • No input file
  • No output file
  • The input file is changed. Procedure
  • The output loss

A recent issue related to this led to long incremental compilation times, mostly in the CompileAsseetCatalog stage.

CocoaPods normally handles resource copies with inputs and outputs to reduce resource import and compile behavior.

There are many private libraries in our project that reference images in the form of assets.xcassets (unwrapped bundles, static libraries), resulting in a compilation error:

Targets which have multiple asset catalogs that aren't in the same build phase may produce an error regarding a "duplicate output file"
Copy the code

Build System Release Notes for Xcode 10

Targets which have multiple asset catalogs that aren’t in the same build phase may produce an error regarding a “duplicate output file”. (39810274)

Workaround: Ensure that all asset catalogs are processed by the same build phase in the target.

The interim solution given above is to process all asset catalogs in the same build process. To add CocoaPods to your Podfile, add the following:

install! 'cocoapods'.:disable_input_output_paths= >true
Copy the code

This setting will turn off input and output in the resource Copy. As mentioned above, without input and output, the resource Copy will be executed each time. Because Pod’s assets. scassets are eventually compiled into car with the main project’s assets. scassets, the main project waits for the Pods Copy to be finished before compiling, even if the resource files have not changed, resulting in an increase in the increment time.

There is an Issue in the CocoaPods repository discussing this Issue: Issue #8122. However, none of the solutions under this answer is applicable. Later, the resource reference mode in the private library is changed to Bundle, and the disable_INpuT_output_Paths setting is removed, and the incremental compilation effect is greatly improved:

The CompileAssetCatalog stage, which takes most of the compilation time, is gone.

Apply Module Maps to your Module

Module Maps mainly shorten header reference problems. When not moduleized, the compiler preprocesses.h header files for each source file. After Module, the compiler does not preprocess. Just make sure DEFINES_MODULE is Yes when making the repository and Xcode will do all the rest.

Note that to take full advantage of Module Maps, you also need to make sure you add the library name to the header reference so the compiler knows you have Module Map.

#import

Not recommended: #import < header. h> or #import “header. h”

Clear project dependencies

Remove unnecessary dependencies, because outdated or redundant dependencies might force Xcode to build sequentially when building in parallel.

Typically when a project introduces a new Framework, Xcode automatically adds corresponding dependencies, which are implicit. Compare recommended Dependencies: in Build Phases -> Dependencies -> click add.

Refactor Target to improve concurrency

Analyze the original build process and remove any additional dependencies. This is a bit more expensive, but in some cases it should make a big difference.

For example: when a target depends on multiple sub-targets, Xcode must wait for all sub-targets to complete before continuing to compile the current target. We can consider splitting dependencies to maximize Xcode’s concurrency.

Parsing the interview

Edit: Xiao Haiteng of Normal University

Q: Execute the following code and what will be printed?

dispatch_async(dispatch_get_global_queue(0.0), ^ {NSLog(@ "1");
    [self performSelector:@selector(test) withObject:nil afterDelay:. 0];
    NSLog(@ "3");
});

- (void)test {
    NSLog(@ "2");
}
Copy the code

The printed results are 1 and 3. The reason is:

  1. performSelector:withObject:afterDelay:Is essentially taking the current thread’s RunLoop and adding a timer to it
  2. Runloops are one-to-one with threads, and runloops are not enabled for child threads by default
  3. The currentperformSelector:withObject:afterDelay:Execute in child threads

So 2 won’t print.

Good blog

SIL: Swift Intermediate Language, SIL is a high-level Intermediate Language. SIL is generated by SILGen and converted from IRGen to LLVM IR. SIL performs high-level semantic analysis and optimization on Swift. Most of the code we see that starts with @ is in the SIL category.

I am Xiong Da, Dongpo Elbow son

Swift’s high-level intermediate language: SIL — from the Simple book: Sea_biscute

Swift compiler design is described in the official LLVM documentation as follows: Swift programming language is built on LLVM and uses LLVM IR and LLVM backend to generate code. But the Swift compiler also includes a new high-level intermediate language called SIL. SIL performs a higher level of semantic analysis and optimization for Swift. This article will analyze the motivation for SIL design and the application of SIL, including high-level semantic Analysis, diagnostic transformation, de-virtualization, specialization, reference counting optimization, TBAA (Type Based Alias Analysis), etc. IR comparisons to SIL and LLVM are also included in some processes.

2. To see the nature of Swift enumeration — from: Fox Friends technical team

Dongpo Elbow: Examples of SIL application in practical work. Explore what the bottom of enumeration looks like by analyzing the memory layout, looking at the SIL source code, and so on. Enumerations in Swift are no longer just a constant to distinguish between types, they have been greatly enhanced. Enumerations can set raw values, add associated values, even add computed properties (not stored properties), define methods, and implement protocols. Second only to a Class object, Swift enumerations can do all of these things.

3. Preliminary Study on Swift Intermediate Language — From Simple Book: Sea_biscute

King Piraf: This article gives a brief introduction to SIL and its place in the LLVM architecture. In the body part, the author uses SIL analysis to explain the selection of protocol function in extension and protocol function call in the object.

Swift compiler SIL — Roy’s Blog

King Pirav: The author first introduces the original design of SIL and the difference from LLVM IR. The concept of generation in STATIC Single-Assignment (SSA) and its benefits are also introduced. SIL is a collection of named functions. The SIL source file is Module, through which you can traverse the functions in Module.

Swift Intermediate Language — A high level IR to Complement LLVM — from Joe Groff and Chris Lattner

I’m Big Bear: Groff and Chris Lattner covered SIL in detail in a presentation at the LLVM Developers conference. Topics include: why to use SIL, design logic for SIL, Swift’s use of SIL, etc. Although the presentation is in English, it is mainly composed of code and diagrams, which are very helpful to understand the design motivation and design principles of SIL.

Learning materials

Mimosa

Flutter Apprentice from raywenderlich

Address: www.raywenderlich.com/books/flutt…

Raywenderlich’s new tutorial on Flutter. The site’s tutorials are always characterized by their simplicity and clarity. If you want to get started with Flutter, this book is a great choice. There’s also a new version of Swift Apprentice on the site for those who want to revisit it.

Handbook of Cognitive Biases

Address: s75w5y7vut. Feishu. Cn/docs/doccn3…

A popular manual of psychological knowledge terms, not about the code, but for Internet workers, after reading may let you better understand the relationship between the product and the user, can improve the details of the product, user experience and so on.

Tools recommended

CoderStar

fig

Address: FIG. IO /

Software status: Free, open source

Software Introduction:

FIG is an open source terminal completion tool that supports hundreds of CLI tools, such as git, docker, NPM and more, and can be seamlessly added to your existing terminals, such as iTerm, Hyper, VSCode and macOS terminals, supporting our own custom completion rules.

About us

IOS Fish weekly, mainly share the experience and lessons encountered in the development process, high-quality blog, high-quality learning materials, practical development tools, etc. The weekly warehouse is here: github.com/zhangferry/… If you have a good content recommendation, you can submit it through the way of issue. You can also apply to be our resident editor to maintain the weekly. Also can pay attention to the public number: iOS growth road, backstage click into the group communication, contact us, get more content.

Phase to recommend

IOS Fishing Weekly 30th issue

IOS Fishing Weekly 29th issue

IOS Fishing Weekly 28th issue

IOS Fishing Weekly issue 27