This profile

  • This topic: Talk about the iOS blogging environment, public accounts vs nuggets.
  • Tips: Reachability, the meaning of JOIN and UNION in SQL, how to distinguish AdHoc and AppStore packages in the project.
  • Block type: block type: block type
  • Good blog: How to do battery optimization, on MetricKit usage.
  • Materials: “Seeing Statistics” by students at Brown University; There are Hacker Laws, a Github repository.
  • An online tool to help you learn regular expressions: Regex101.

This topic

Zhangferry: Look at a picture of the author list of recent nuggets

As can be seen from the above figure, there are many authors with public accounts on the top front end and Android end of Nuggets, but not on iOS end. On the other hand, there are a lot of team numbers on both the front end and the top end of Android, while on iOS it’s all about individual creators. Because the rankings are based on recent trends in article activity, they are somewhat contingent, but there are some clues. Here are some of the points I’ve come up with (referring only to the mining platform) :

  • Senior author not active: iOS big (high level number) is not active in writing, or by accident, big is dormant for the next post.
  • Writing environment does not filter: iOS writing environment is not good, this has a long history, has been mainly interview articles, some training institutions will even nuggets as a platform for students to practice, really share project experience, practice is less.
  • The creation environment is difficult to break through: the gold digging platform needs to be recommended to have a higher amount of light exposure. Meanwhile, iOS authors are less likely to write public accounts.
  • IHTCboy: iOS system is closed, so the API provided by Apple is unified and perfect. There have been many articles on most API networks, while the front-end and Android need more technical exploration due to the compatibility and openness of the system and the number of mobile phone manufacturers.

The whole reaction is that the iOS community isn’t active, but is it? Just for the WWDC21 internal reference organized by the old driver weekly newspaper some time ago, there were 200+ participants, and the community must be active. So I’ve come to the conclusion that public accounts are better than Nuggets in the iOS blogging environment.

The development of Tips

5, zhangferry

ReachabilityPractice guidelines for class

In network request practices, it is common to monitor the state or transformation of Reachability to selectively judge the network accessibility and make corresponding operations to block or suspend requests.

Under the influence of network status monitoring, when users perform certain operations, they can prevent users from making network requests when the network is NotReachable based on the current network status of the users.

That is until I read the Docs on Reachability phenomerna Apple’s Docs in AFNetworking Issues.

We should not use Reachability as a judgment on whether the network is available, because in some cases the status returned may not be as accurate.

AFNetworking defines best practices regarding Reachability:

Reachability can be used to determine background information about why a network operation failed, or to trigger a network operation retrying when a connection is established. It should not be used to prevent a user from initiating a network request, as it’s possible that an initial request may be required to establish reachability.

We should use it for background information after a failed network request, or to determine if it should be retried after a failure. Should not be used to prevent users from making network requests, as the request may need to be initialized to establish reachability.

Reachability, which we have integrated in network requests, should be used after a request fails, either as a reminder of a failed request or as a condition for the request to retry using changes in the Reachability status.

When we use AFNetworkReachabilityManager or functionally similar Reachability class, we can be based on this to get the current network types, such as 4 g or WiFi. However, when we monitor that the status becomes unreachable, we should not immediately pop up Toast to tell the user that the current network is unavailable. Instead, we should judge whether the status is unreachable after the request fails. If so, we will prompt the user that there is no network. And, if the interface needs some consistency, it can keep the current request parameters and prompt the user to wait until the network is reachable.

JOIN and UNION in SQL

LEFT JOIN, RIGHT JOIN, INNER JOIN, OUTER JOIN, LEFT JOIN, RIGHT JOIN, LEFT JOIN, OUTER JOIN. Corresponding to the representation of the set, they will appear in the following 7 representations:

UNION: combines multiple SELECT results. UNION will merge the same values by default, and you can use UNION ALL if you want to display the results one by one.

Here is a scenario: three tables: Table1, table2, table3, they share the same ID, Table2 and table3 are two end data interface exactly the same data, I now want to a certain number of columns in Table1, to view the corresponding to table2 and table3 associated with several columns of data. The SQL statement is as follows:

select 
  t1.id
	t1.column_name1 as name1,
	t1.column_name2 as name2,
  t2.column_name3 as name3,
  t2.column_name4 as name4
from 
	(
	select 
    id,
		column_name1,
     column_name2
	from 
		table1_name
	) t1
left join 
	(
	select 
		union_table.* 
	from
		(
        select 
            id,
            column_name3,
            column_name4
        from 
            table2_name
        union all 
        select 
            id,
            column_name3,
            column_name4
        from 
            table3_name
        ) union_table 
	) t2 on t1.id = t2.id
Copy the code

Differentiate between AppStore/Adhoc packages in your project

Before solving this problem, we need to understand the concept of development environment. The development environment of iOS usually involves three dimensions: project, developer server, and AppStore server.

project

Our Xcode Project, managed by Configuration in Project, has two development environments by default: Debug and Release. The macro commands we commonly use to control the development environment, such as DEBUG, are preset values by Xcode for us. Its setting form is DEBUG=1, and the contents here can be modified.

We added a Configuration called AppStore and gave it a macro AppStore =1, and then set the previous Release to ADHOC=1, specifying specific macros for both project environments.

Development-side server

The server environment is managed by the server side, reflected in the project, and we usually align it with the project environment.

AppStore server

The development environment of AppStore is determined by the form of certificate, which determines the application scenarios of IAP and push. In the final package sealing process, Xcode divides it into the following four scenarios:

It can be seen that Configuration Settings and packet sealing are independent of each other. If there are three configurations locally, the maximum number of package types that can be exported is: 3 x 4 = 12. Therefore, it is not enough to describe the type of a package only with the development package and the build environment package, but the full description is not realistic, and because the package is compiled, we cannot determine the package type in advance, so we have some conventions and conventions.

Development package usually refers to: Debug + Development,

Production environment packages usually refer to: Release + Ad Hoc or Release + App Store Conenct

As the title says, if we want to distinguish between Ad Hoc and AppStore, we need to add Configuration: AppStore.

Ad Hoc package: Release + Ad Hoc

AppStore Package: AppStore + AppStore Connect

In this code we can configure Ad Hoc and AppStore separately using the macros we defined above.

Since they are conventions, there is no strong correlation between them, so it is recommended to use scripts to package them to avoid human-caused errors.

Note: As suggested by @ihtcboy, it is also possible to distinguish package types in the form of non-Configuration. Part of the content has not been implemented yet, and the solution will be put into the next content after the test.

Parsing the interview

Edit: Xiao Haiteng of Normal University

This section explains block types. Have you ever had an interview question like:

  • What are the types of blocks?
  • What’s wrong with stack blocks?
  • What is the result of each type of block calling copy?

I hope the following summary can help you. If you have any questions about the content, or have better answers, please feel free to contact us.

Block type

There are three types of blocks: stack blocks, heap blocks, and global blocks, all of which ultimately inherit from the NSBlock type.

Block type describe The environment
__NSGlobalBlock__

(_NSConcreteGlobalBlock)
Global block, stored in data segment (.data segment) Defined in a global zone or without access to automatic local variables
__NSStackBlock__

(_NSConcreteStackBlock)
Stack block, stored in the stack area Access automatic local variables
__NSMallocBlock__

(_NSConcreteMallocBlock)
Heap blocks, stored in the heap area __NSStackBlock__Call the copy

1. The stack

When a block is defined, the area of memory it occupies is allocated on the stack. A block is valid only in the scope in which it is defined.

void (^block)(void);
if ( /* some condition */ ) {
    block = ^{
        NSLog(@"Block A");
    };
} else {
    block = ^{
        NSLog(@"Block B");
    };
}
block();
Copy the code

There is a danger in the above code that the two blocks defined in the if and else are allocated in stack memory, and when out of the if and else range, the stack block may be destroyed. If the compiler overwrites the block’s memory, calling the block causes the program to crash. Or the data may become junk, even though the block can be called in the future, but the values of the variables it captures are out of order.

Under ARC, the upper block is automatically copied to the heap, so there should be no problem. But we want to avoid that under MRC.

2. The pile of blocks

To solve this problem, a block object can be copied from the stack to the heap by sending a copy message. The heap block can be used outside of the scope in which it is defined. Heap blocks are reference-counted objects, so under MRC if heap blocks are no longer used you need to call Release to release them.

void (^block)(void);
if ( /* some condition */ ) {
    block = [^{
        NSLog(@"Block A");
    } copy];
} else {
    block = [^{
        NSLog(@"Block B");
    } copy];
}
block();
[block release];
Copy the code

3. The global block

A block is global if all the information needed to run it can be determined at compile time, including no access to automatic local variables. Global blocks can be declared in global memory and do not need to be created on the stack each time they are used. A copy operation for a global block is null because the global block can never be reclaimed by the system and is effectively a singleton.

void (^block)(void) = ^ {NSLog(@"This is a block");
};
Copy the code

Each type of block calls copy as follows:

Block type The configuration storage area of the copy source Print effect
_NSConcreteGlobalBlock The data section of the program (.data section) Do nothing
_NSConcreteStackBlock The stack Copy from stack to heap
_NSConcreteMallocBlock The heap Reference count increment

Reference: iOS interview parsing | block type

Good blog

King Pilaf is here. I am Xiong Da

The topic of this issue: Battery optimization

1. Power consumption detection for iOS performance optimization — from: grocery store

This paper introduces three kinds of power consumption detection methods: Energy Impact, Energy Log and sysDiagnose. The detection steps are described in detail for each scheme. It is mentioned in the Energy Log that “if CPU threads occupy more than 80% continuously for three minutes on the front desk or one minute on the back desk, it will be judged as power consumption, and the stack of power consumption threads will be recorded for analysis”, which is helpful for our daily analysis.

2, Analyzing Your App’s Battery Use — from Apple

Apple provides some performance monitoring tools. Xcode Organizer allows you to view 24 hours of performance data, including battery life.

3. IOS performance optimization: Using MetricKit 2.0 to collect data — from veteran Driver Weekly: Jerry4me

Since the official solution is mentioned, MetricKit has to be mentioned. This article introduces what MetricKit is, how to use it, and the new data metrics coming with iOS 14. It is also important to note that MetricKit was not supported until iOS13, and does not collect data from all users. Only users who share iPhone analytics can collect data.

4. IOS Advanced –App power optimization — from Cocoachina: YyuuZhu

Intuitive power consumption mainly includes: CPU, device wake up, network, image, animation, video, motion sensor, positioning, bluetooth. Test tools: Energy Impact, Energy Log, see this article for more details.

5. A new framework for iOS power consumption and performance optimization — from Punmy

In Session 417, Apple introduced three new power and performance monitoring tools, one for development, one for in-beta, and one for online. After reading this article, you will have a better plan for how to optimize your App’s power consumption and performance.

6. Suggestions for power Consumption Optimization — from the blog Catalog

Some practical suggestions on optimizing power consumption.

Learning materials

Mimosa

Seeing Theory

Address; seeing-theory.brown.edu/cn.html

The Seeing Statistics course, developed by students at Brown University, aims to use data visualization to make mathematical statistical concepts easier to understand. The content of the course is roughly similar to that of probability theory and mathematical statistics in domestic undergraduate courses, and the localization support for Chinese is very good.

Hacker Laws

Address: github.com/dwmkerr/hac…

We often talk about “xx law”, “XX law”, such as “Moore’s Law” and so on. In the Hacker Laws repository, you can find rules and Laws that are well-known or common in the developer community. But be warned: this repository contains explanations of some laws, principles, and patterns, but does not advocate any of them. Whether or not they should be used depends a lot on what you are doing, and use them accordingly.

Tools recommended

zhangferry

regex101

Address: regex101.com

A regular expression testing and analysis site that not only outputs match results, but also analyzes the meaning of each expression. We test with the copy about us in Moyu Weekly. We want to match the two strings of “iOS Moyu Weekly” (with space in the middle) and “iOS growth road”. A copy must start with “iOS”, cannot be followed by other letters, and end with a comma but not including a comma. The test results are as follows:

Observe the result analysis on the right, using the *? The non-greedy model and (? = 0, 0, 0, 0, 0, 0, 0 This is a great way to understand regular expressions written by others.

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 21st issue

IOS Fishing Weekly 20th issue

IOS Fishing Week issue 19

IOS Fishing Weekly issue 18