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.

The development of Tips

Edit: the devil seven seven

CocoaPods Common operations

pod install

This command is used when our project first uses Cocoapods to manage third-party libraries or whenever we edit a Podfile, such as adding, deleting, or editing apod library.

  • For the first time to performpod installCommand to download and install new pods and write the version of each pod to your podfile. lock file. This file keeps track of all POD libraries and their dependent versions and locks their version numbers.
  • Execute in the presence of podfile. lockpod installResolves only pod dependencies that are not listed in podfile. lock. 1. For versions listed in Podfile.lock, install the existing version without checking for updates to your Pods. 2. If the version is not listed in podfile. lock, it will be installed according to the version described in Podfile.

The Podfile file is the core of pod execution.

pod update

Pod Update can be upgraded globally, or podName can be specified as a single update. When we execute pod update podName, we ignore the version of the podfile. lock file, update it to the latest version as defined by the Podfile, and update the podfile. lock file. This command also applies to dependencies defined inside the POD library PodSpec file. Outdated versions of dependencies and upgradable versions can be detected through POD outdated.

There are two common parameters for install and update:

  • — Repo-update: This directive will update all the repOS, such as a private library version of the update, direct install will not find the corresponding version, we do not want to update all dependent libraries, just update the corresponding repO, can use this directive. This parameter also corresponds to a specific command:pod repo update.
  • –no-repo-update: The update operation updates all repOs by default. Sometimes this is not necessary and the step synchronizes the POD public REPO, which is time-consuming, so you can add this parameter to turn off the update operation.

Suggestions for using CocoaPods

  • It is recommended to use Gemfile to manage pod versions, each time pod is executed through bundles, for example: Bundle exec Pod install.

  • When the project holder manager CocoaPods the project, there is a podfile. lock file that we need to put into version control.

  • If a library needs to be updated to a certain version, the project holding manager updates the library to a certain version using pod Update podName. Then submit the podfile. lock and Podfile files.

The Bug

zhangferry

Module compiled with Swift 5.3.2 cannot be imported by the Swift 5.3 Compiler: **. Swiftmodule

The problem background

This error occurs when a Swift library (Framework) generated by one version of Xcode is not recognized on another machine (different version of Xcode).

Problem analysis

Module compiled by Swift 5.3.2 (the version of the compiler can be viewed by Swift –version), specifically swiftModule file, is not recognized by Swift 5.3 compiler. The SwiftModule file is used to describe Swift’s internal method declarations. It is in binary format and generates different versions for different architectures. But because of its binary format nature, it cannot be adjusted as the compiler upgrades. This problem corresponds to Module stability in ABI stability. Here’s a quote from Cat God’s blog:

ABI stability is a necessary but not sufficient condition for using binary publishing frameworks. The binary of the framework is compatible from runtime to runtime, but the framework now relies on a.swiftModule binary to describe the API Interface. This binary contains the serialized AST (more specifically, SIL for interface), and the platform environment (Swift compiler version, etc.) in which this Module was compiled.

ABI stability does not mean compilation toolchains are stable. For frameworks to provide a framework in binary, in addition to binary itself being stable, the way binary is described (now swiftModule) also needs to be stable, which is under development. In the future, Swift will provide a text.swiftInterface for the Module as a framework API description, and then let future compilers “compile” the corresponding.swiftModule from this description as a cache and use it.

This goal is called Module Stability, and when it is achieved, you can publish the framework using Binary.

Problem solving

Module Stability has been implemented by using the.swiftInterface file to describe binary packages. Enable-library-evolution (Build Libraries for Distribution, YES) The resulting Framework contains the corresponding.swiftInterface file, which enables compatibility between different versions of compilers.

But that’s not the end of the story. There’s another problem:

/*.framework/Modules/*.swiftmodule/arm64-apple-ios.swiftinterface:5:8: cannot load underlying module for 'SnapKit'

failed to build module '*' from its module interface; the compiler that produced it, 'Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)', may have used features that aren't supported by this compiler, 'Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
Copy the code

Swiftinterface should not cause compile incompatibility issues, but it does, although the message is slightly different and there is an internal dependency library issue. Here is the swiftInterface file of the corresponding version:

// swift-interface-format-version: 1.0 // swift-compiler-version: Apple Swift Version 5.3.2 (Swiftlang-1200.0.45 clang-1200.0.32.28) // swift-module-flags: -target arm64-apple-ios10.0 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked  -Onone -module-name ZYModule import Foundation import SnapKit import Swift import UIKitCopy the code

Build Libraries for Distribution (SnapKit); Build Libraries for Distribution (SnapKit); Build Libraries for Distribution (SnapKit) SnapKit compiled using source code in the project is inconsistent with its current compiled version (5.3) and the version generated by the binary library (5.3.2), thus causing the problem. I tried to change the Build Libraries for Distribution option of the Pod library in the project:

post_install do |installer|
  installer.pods_project.targets.each do |target|
   target.build_configurations.each do |config|
    config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
   end
  end
end
Copy the code

Problem solved, compile passed!

Programming concepts

Shi da haiteng, zhangferry

What is the BIOS

The BIOS is called Basic Input/Output System. BIOS is pre-built in the computer host internal procedures, but also the computer boot loaded after the first program. The BIOS stores the computer’s most important basic input and output programs, self-check programs after startup, and system self-start programs. It can read and write specific information about system Settings from the CMOS (a piece of RAM chip that can be read and written on the computer motherboard).

BIOS in addition to keyboard, disk, graphics card and other basic control programs, there are boot program functions. The boot program is a small program stored in the start area of the boot drive, which is usually a hard disk. But sometimes it could be a CD-ROM or floppy disk.

After the computer is powered on, the BIOS will check whether the hardware is running properly. If there is no exception, the BIOS will directly start the boot program. The function of the boot program is to load the OS recorded on the hard disk into the memory and run it.

Clover, installed while making the Black Apple, is a boot application that modifies the BIOS configuration so that the BIOS executes it first and then boots to MacOS boot.

Strictly speaking, BIOS is a design specification of IBM PC architecture. Mac computers, including some new motherboards, do not have BIOS. Instead, THEY use EFI/UEFI.

What is assembly

Assembly Language is any low-level Language used in electronic computers, microprocessors, microcontrollers, or other programmable devices. It is also called symbolic Language. In assembly language, the use of mnemonics to replace the opcodes of machine instructions and address symbols or labels to replace the addresses of instructions or operands. In different devices, assembly language corresponds to different sets of machine language instructions, which are converted into machine instructions through the assembly process. Specific assembly language and specific machine language instruction set are one-to-one correspondence, different platforms can not be directly transplanted.

Assembly language is more readable than machine language, but it is still less readable than high-level languages. However, the program written by it has the characteristics of less storage space and fast execution, which can not be replaced by high-level languages. In practical application, whether to use assembly language depends on specific application requirements, development time and quality. Common instructions for assembly are as follows:

opcode The operand function
mov A, B Assign the value of B to A
and A, B Add both A and B and assign the result to A
push A Store the value of A on the stack
pop A Read the value from the stack and assign it to A
call A Call function A
ret There is no Processing is returned to the calling source function

What is a virtual machine

A Virtual Machine is a complete computer system with complete hardware system functions that is simulated by software and runs in a completely isolated environment. Everything that can be done in a physical computer can be done in a virtual machine. When creating a VM on a COMPUTER, use part of the physical machine’s hard disk and memory capacity as the VM’s hard disk and memory capacity. Each VM has its own CMOS, hard disk, and operating system, and can be operated as a physical vm.

VMS are used for:

  1. Demo environment, you can install a variety of demo environment, easy to do a variety of examples
  2. Keep the host running fast and reduce unnecessary junk installations, occasional applications, or test applications running on the virtual machine
  3. Avoid each reinstallation, bank and other common tools, not often used, and requires secrecy is better, run under a separate environment
  4. If you want to test unfamiliar or risky applications, install them on the VM and delete them completely
  5. Experience different operating systems, such as Linux and Mac.

VMS can be divided into three categories:

  • System VMS, for example, VMware
  • Program Virtual machines, such as JVM (Java Virtual Machine)
  • Operating system layer virtualization, for example, Docker

What is a peripheral interrupt

IRQ (Interrupt Request) stands for Interrupt Request. IRQ is the necessary mechanism for suspending a currently running program and jumping to another program. This mechanism is called handling interrupts. Interrupt handling plays an important role in hardware control. If there is no interrupt processing, processing may not be smooth.

Processing of the interrupted program (main program) stops from the beginning of the interrupt processing until the program requesting the interrupt (interrupt handler) finishes running. This situation is similar to a phone call in the middle of processing a document, which is equivalent to interrupting processing. If no interrupt processing occurs, you must wait until the document processing is complete before answering the call. Thus, interrupt processing is of great value. Just as the original document job is returned after the call is answered, the interrupt program is returned to the main program after processing.

The INTERRUPT request is performed by the I/O controller connected to the peripherals, and the INTERRUPT processing is performed by the CPU.

If there are multiple peripherals for interrupt requests, the CPU needs to make a choice to process, so we can add an IC named interrupt controller between the I/O controller and the CPU to buffer. The interrupt controller passes interrupt requests from multiple peripherals to the CPU in an orderly fashion. The interrupt controller functions as a buffer. The following is a schematic of the interrupt controller function

What is the DMA

DMA stands for Direct Memory Access. DMA is a memory access mechanism that allows peripheral devices to transfer data directly to main memory without passing through the CPU. Hard disks and other hardware devices use DMA mechanisms. Through DMA, a large amount of data can be transferred in a short time. It is so fast because the TIME of the CPU as the intermediary is saved

I/O port number, IRQ, DMA channel is a three-point combination for identifying peripherals. However, IRQ, DMA channels are not available on all peripherals. The minimum amount of information a computer host needs to control hardware through software is the I/O port number of the peripheral device. IRQ is only required for peripherals that require interrupt handling, DMA channels are only required for peripherals that require DMA mechanisms.

Good blog

Edit: King Pilaf is here

The topic of this blog roundup is Watchdog

1. IOS watchdog — from Jane: Mr_Xie

Let’s start with a brief understanding of what a watchdog is.

2. IOS App background task pit — from Cocoachina: Mimi Dog

Background task leakage is one of the common situations that trigger the watchdog, and there is another situation that the main thread is stuck, the article describes how to distinguish.

Addressing Watchdog Terminations

Apple’s official documentation. Personally, understanding the meaning of scene-create and scene-update plays a certain role in troubleshooting problems.

4. Did your App get stuck on iOS 13

In practice, we rarely actually do a lot of time-consuming operations like network requests on the main thread. Triggering a watchdog is often accidental, and you don’t even suspect that there is anything wrong with your code. This article describes how the 58.com team located the startup jam caused by the clipboard.

5. IOS stability problem governance: monitoring principle and best practice of stuck crash

This article, published earlier by bytedance’s APM team, is one of the few in the industry to publicly introduce the cause of the gridlock crash, which has a strong reference significance. In the process of startup stuck optimization, we basically encountered all the related problems mentioned in the article, but we did not know the reasons and how to solve them before. So if you want to do stuck governance, you can refer to this article.

6. After interviewing over 500 candidates, I want to talk about some expectations from the interviewer’s perspective

The author of “iOS Stability Problem Governance: Principles and Best Practices for Monitoring Gridlock Crashes” wrote this post after interviewing over 500 candidates.

7, argument: iOS security, why need audit?

@ iHTCboy: This paper analyzes the security of iOS from the perspective of debate, compares it with the security of macOS, and puts forward suggestions to make iOS more secure. At the same time, it also summarizes a lot of knowledge of iOS and macOS security technology, which can make everyone quickly start and review the security knowledge of Apple OS in a short time.

Learning materials

Mimosa

Meow god: New book, start!

Meow God’s book on Async-Swift has started. It is about coroutine, a new feature of Swift5.5, and we will inform you through weekly report as soon as the book is completed.

30 seconds of code

Address: www.30secondsofcode.org/

The site’s tagline is: “Find the snippet that will satisfy all your development needs!” , it has Code Snippets for many languages, such as sorting algorithm, hex to RGB, time conversion, etc. It makes it easy for you to find these common Code for each language, making your development efficiency greatly improved! (Unfortunately, there is currently no Swift section 🥲

Tools recommended

zhangferry

Whatpulse

Address: whatpulse.org/

Software status: basic functions are free, advanced functions are paid

Used to introduce

Whatpulse is a computer usage monitor and statistics software. It collects details of your daily keyboard, mouse, Internet usage and puts them into simple statistical tables to analyze your daily computer usage.

The e retention results of nearly a year of using the software on a previous company computer showed that the delete key was the most used.

OctoMouse

Address: konsomejona. Making. IO/OctoMouse/I…

Software status: Free, open source

Used to introduce

The software is mainly used for statistics of keyboard and mouse behavior information, more interesting is that its statistics on the mouse will include moving distance parameters. Try to see how long it takes to move the mouse 5km.

Contact us

IOS Fishing Weekly Issue 8

IOS Fishing Weekly Issue 9

IOS Fishing Weekly issue 10

IOS Fishing Weekly eleventh issue

IOS Fishing Weekly issue 12