IOS Fishing weekly, mainly to share the experience and lessons encountered in the development process and learning content. Although it is a weekly newspaper, the current way of contributing content has not been stable. If there is less than one issue of subsequent content, it may be postponed to the next week. So I hope you can share your own development tips and bug solving experiences.

The weekly warehouse is here: github.com/zhangferry/… , you can see README to learn how to contribute. Also can pay attention to the public number: iOS growth road, backstage click into the group communication, contact us.

The development of Tips

Development tips included.

YYModel parsing data provides default values

When parsing JSON data using YYModel in OC, data that does not exist or returns null is treated as nil. And sometimes we might not want that field to be set to nil, but we might want to provide a default value, like NSString, which returns @”” if it doesn’t parse, empty string. This does not cause crashes in scenarios where you need to pack specific parameters into NSDictionary or NSArray, and also saves some of the null-detection code.

Achieving this requires two steps:

1. Find the properties of the property type

You can use the property_copyAttributeList method provided by Runtime:

static const char *getPropertyType(objc_property_t property) {
    // You can also use YYClassPropertyInfo to get the corresponding data
    unsigned int attrCount;
    objc_property_attribute_t *attrs = property_copyAttributeList(property, &attrCount);
    if (attrs[0].name[0] = ='T') {
        return attrs[0].value;
    }
    return "";
}
Copy the code

Attrs [0]. Name [0] == ‘T’

Other encoding types can be found here.

You can replace the attributes you need to replace, using the KVC form:

[self setValue:obj forKey:propertyName];
Copy the code

2. Replace the default values when the JSON Model is completed

Where should I write this function? I found this method in NSObject+ yyModel.h:

- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic;
Copy the code

This method is used to verify that the converted Model is as expected. At this point, the Model has completed the transformation and we can call the default value replacement method written above.

Encapsulation using

I’ve already written an implementation, and here’s the code.

To do this, we simply refer to the NSObject+ defaultValue. h header in the Model class and implement this method:

- (YYPropertyType)provideDefaultValueType {
    return YYPropertyTypeNSString;
}
Copy the code

Indicates that we need to replace all attributes in the class with empty strings when they don’t exist.

Note: YYModel has an issue about this, but according to the author, this extension should not be put in this library, so it is not mentioned as PR.

Architecture changes supported by iOS11

The i386 architecture is little used now. It is Intel’s 32-bit architecture and will be used for the iPhone5 and below emulators. Not much is used, but many scripts (such as CocoaPods) require support from this architecture. Xcode12 has removed the emulator from the iPhone5, and if you want to ship a package with this architecture, it won’t work by default. We can set Debug in Build Active Architecture Only to NO in Build Setting, so that the package is compiled with all architectures, including i386.

However, when we set the minimum supported version of the package to iOS11 and above, there is no i386 package compiled at this time, it is likely that Apple has removed the architecture. If we still need to export the schema, we need to specify the schema implementation with the xcodeBuild command, which is as follows:

$xcodebuild -project ProjectName.xcodeproj -target TargetName -sdk iphonesimulator -arch i386 -configuration Debug -quiet  BUILD_DIR=build
Copy the code

Programming concepts

What is a relational database

Relational database refers to a database that uses a relational model to organize data.

Relational model was first proposed by IBM researcher Dr. E.f. Cod in 1970. In the following decades, the concept of relational model has been fully developed and gradually become the mainstream model of the mainstream database structure.

To put it simply, a relational model is a two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and their relationships.

Relational databases are represented by SQL Server, Oracle, and Mysql

Their advantages are easy to understand, two-dimensional table structure is more close to the real world, it is also very convenient to use, the use of general SQL statements can be completed to add, delete, change, check and other operations. Another big advantage of relational database is its integrity and reliability, which greatly reduces the probability of data redundancy and data inconsistency.

However, a lot of things have two sides, and relational databases are no exception. When dealing with high concurrency, usually tens of thousands of read and write requests per second, hard disk I/O will face a big bottleneck problem.

What is a non-relational database

Non-relational databases, also known as NoSQL, are used to distinguish relational databases that rely on SQL statements. NoSQL has another interpretation: Not only SQL.

Non-relational database is mainly used to solve the high concurrent read and write bottleneck of relational database. There are many kinds of this kind of database, but they all have one thing in common, that is to remove the relational characteristics of relational database, so that the expansion of database is easier.

However, it also has certain disadvantages that there is no transaction processing, the data structure is relatively complex, and the processing of complex queries is relatively insufficient.

Non-relational database can be divided into four categories:

Document: Used in Web applications, such as MongoDB and CouchDB

Key-value: Processes a large amount of data with high access load and content caching, such as Redis and Oracle BDB

Column database: Processes distributed file systems, such as Cassandra and HBase

Graph database: used for social network, recommendation system, typical examples are Neo4J, InfoGrid

SQL and NoSQL are not stronger than each other, NoSQL will not replace SQL, only combined with their own business characteristics to play the advantages of the two types of database.

What is ACID

ACID refers to four characteristics that a database management system must have to ensure transaction reliability when writing or updating data. A (atomicity) is atomic: all operations in A transaction either complete or not complete, there is no intermediate state, and if there is an error in the intermediate process, it is rolled back to the state before the transaction started.

C (consistency) : Database integrity is not compromised before and after a transaction.

I (Isolation) Isolation: The ability of a database to allow multiple concurrent transactions to read, write, and modify its data at the same time. Isolation prevents data inconsistency caused by cross-execution when multiple transactions are executed concurrently.

D (Durability) : Modifications to data are permanent after transactions, they are not lost even if systems fail. Relational databases generally adhere to these four features, while non-relational databases usually break some of the four features to achieve high concurrency and easy to scale.

What is a database paradigm

To put it simply, the paradigm is to eliminate duplicate data and reduce redundant data, so as to make the data in the database better organized, so that the disk space can be more effective use of a standardized specification, the prerequisite to meet the high-level paradigm is to meet the low-level paradigm. (For example, satisfying 2NF must satisfy 1NF).

At present, there are six paradigms: first paradigms (1NF), second paradigms (2NF), third paradigms (3NF), And Bas-Coad paradigms (BCNF). Fourth paradigms (4NF) and fifth paradigms (5NF) are also known as perfect paradigms. NF is short for Normal form, which translates as Normal form.

1NF means that each attribute is not divisible. A database that does not conform to the first normal form cannot be called a relational database.

2NF requires that each instance or record in a database table must be uniquely locatable.

3NF requires that one relationship does not contain non-primary keyword information that is already contained in other relationships.

BCNF is based on 3NF, any non-primary attribute cannot depend on primary key subsets (eliminate dependency on primary code subsets based on 3NF)

4NF is to eliminate multi-value dependencies in tables, that is, to reduce the effort to maintain data consistency.

If it is in 4NF and does not contain any connection dependencies and the connection should be lossless, then the relationship is in 5NF.

The higher the standard used, the more tables there are, and the more tables there are, the higher the query complexity. The standard used depends on the actual situation, usually satisfying the BCNF.

What is an ER diagram

ER Diagram is short for Entity Relationship Diagram, also known as Entity Relationship Diagram. It is mainly used in the conceptual design stage of database design to describe the Relationship between data.

It has three main elements:

1. Entity: Represents data objects, represented by rectangles

2. Properties: Indicates the properties of the object, represented by ellipses

3. Connection: refers to the relationship between entities, which is represented by a diamond. There are three kinds of association relations: 1:1 refers to one-to-one, 1: N refers to one-to-many, and M: N refers to many-to-many.

Use straight lines to connect connected parties.

Horizontal lines indicate keys, double rectangles indicate weak entities, and the transcript is dependent on the student and cannot stand alone.

What is a database index

An index is a data interface that sorts the values of one or more columns of a database table. The use of indexes can speed up the search of data, but it also has a price, it will increase the database storage space, increase the time to insert, delete, modify data.

The reason why the database index can improve the search efficiency is that the index is organized in the form of B+ tree (or other balanced tree). B+ tree is a multi-fork balanced tree, which can use the principle similar to binary search to search for data. For a large number of data, it can significantly improve the search efficiency.

Because of the use of balanced trees, deletion and addition of data can break the balance of the original tree, so the data structure needs to be reorganized to maintain balance, which is why increasing the index takes time.

For non-clustered indexes (non-primary key field indexes), the field data is copied and used to generate the index, thus increasing storage space. The lookup of a non-clustered index is to find the specified value, then use the additional primary key value, and then use the primary key value to find the desired data through the clustered index.

Reference: B+ tree details

Good blog

Functions Throttle and Debounce parsing and their OC implementation — the path to iOS growth

2021 Ali Tao Department Engineer Recommendation list — from the public number: Tao Department technology

Analysis of bytedance’s solution to OOM’s online Memory Graph technology implementation — from Nuggets: a bit of a feature

IOS Stability Issues governance: Deadlock crash monitoring principles and best Practices — from Nuggets: Bytedance Technology Team

An iOS fluency optimization tool — from the Nuggets: BangRaJun

IOS anti-hacking false positioning detection technology — from Nuggets: Ouyang Big Brother 2013

The official release of Flutter 2.0 is Stable on all platforms

How to make a high quality sharing — from Nuggets: Xiang Senior

Learning materials

IOS Developer Resources

Recommended source: CAT13954

This document is aimed at almost all resources related to iOS development on the market for reorganization, integration and supplement, more suitable for domestic developers.

The document content contains dozens of sets of tutorials, thousands of frameworks, countless tools, websites, information and so on, currently a total of 4600+, covering and iOS learning, daily work related to all aspects, whether iOS novice, or veteran, is worth collecting a resource document.

For beginners, you can browse the document first, have a complete impression of the entire iOS ecosystem in advance, open your horizon, save a lot of time for future study and work, and take fewer detours.

For veterans, the content layout has also been optimized for easy lookup, Star has been highlighted for github open source projects for easy filtering, and Swift support projects have been marked accordingly.

Tools recommended

Good tools are recommended.

F.lux

Recommended source: Zhangferry

Address: justgetflux.com/

Software status: Free

Used to introduce

The monitor brightness of the computer is the whole day to keep constant commonly, this brightness does not have any problem to use during the day, but to use at night, there will be some dazzling, for the protection of vision, at night should let the screen brightness a few lower, a few warmer.

F. Lux deals with this problem by adjusting the color of the screen according to the time of day, so that it looks like sunlight during the day and looks more like indoor light at night.

Kap

Recommended source: Highway

Address: getkap. Co /

Software status: Free, open source

Used to introduce

An open source and simple and efficient screen recording software, can be exported to GIF, MP4, WebM, APNG and other formats, and will have a very good compression rate.

In view of the two restrictions of GIF on wechat public account:

1. No more than 300 frames

2. The size cannot exceed 2M

We need to clip and compress some giFs to upload.

An easy way to Delete frames is to open a GIF using Mac preview, select the frame you want to Delete, and press Command + Delete to Delete the frame. In addition, if multiple consecutive frames are selected, you can select the first frame and then hold down Shift to select the last frame to select all consecutive frames within this range.

For GIF compression, another tool is recommended: docsmall.

docsmall

Recommended source: Zhangferry

Address: docsmall.com/gif-compres…

Software status: Free, Web

Used to introduce

Upload the GIF file to be compressed

Contact us

The third issue of Fishing Weekly

Fishing Weekly Issue 4

The fifth issue of Fishing Week