This profile

  • Xiaobian collated some guide to flood response, I hope to help you.
  • The Tips section describes how to draw a statistical graph of a high appearance level.
  • Deep copy shallow copy
  • Good blog has put together some great articles on package size optimization.
  • The study materials recommend Better Explaine as a site to help you understand complex mathematical concepts.
  • Screenshot tool Snipaste, useless image search tool LSUnusedResources

This topic

@zhangferry: The recent henan flood has been affecting the heart, flood discharge is an effective measure to control the flood, the main place of zhengzhou flood discharge has Henan Zhoukou, downstream is anhui boundary head and Fuyang. I am from Zhoukou, Henan province, and my daughter-in-law is from Fuyang, Anhui Province. When we learned about the situation in our hometown, we both felt distressed and proud.

Although the natural disaster is ruthless, but there are a lot of moving things, one side is difficult eight parties to support, for each involved in henan flood relief personnel to pay the highest respect. Up to now the flood has not completely receded, can not be taken lightly. Here are some guidelines I’ve compiled from official news reports to help you cope.

Finally, henan refueling, Anhui refueling!

The development of Tips

Code a statistical graph of high appearance level

Editor: FBY

There are some requirements in project development that cannot be met only by displaying them in lists. If they are presented in the form of charts, data changes can be obtained more quickly. For the most part, we use third party charting tools. Here is a simple manual chart that supports three types of graphs: line charts, bar charts, and circle charts.

Results show

Analysis of the realization of broken line statistical graph

It is observed that the line chart consists of several parts: the X-axis, the Y-axis and their scale, the background auxiliary line, the line representing the trend and the inflection point of the circle, and the overall gradient under the line.

1. UIBezierPath is used to describe the path of x axis and Y axis; CAShapeLayer is used to set the color and dotted line style; label is used to represent UILabel; the spacing of each punctuation mark should be paid attention to.

2, background auxiliary line and trend line draw the same as the coordinate axis, the only difference is that the trend and style of the line segment is slightly different.

3, gradient scheme overall gradient, and then let the bottom of the line chart as a mask to achieve.

The bar chart and the pie chart design ideas are similar, you can think for yourself, the complete code can be viewed here: FBYDataDisplay-iOS. Here is sample code for a broken line:

#pragmaMark draws the graph
- (void)drawChartLine {
    UIBezierPath *pAxisPath = [[UIBezierPath alloc] init];
    
    for (int i = 0; i < self.valueArray.count; i ++) {
        
        CGFloat point_X = self.xScaleMarkLEN * i + self.startPoint.x;
        
        CGFloat value = [self.valueArray[i] floatValue];
        CGFloat percent = value / self.maxValue;
        CGFloat point_Y = self.yAxis_L * (1 - percent) + self.startPoint.y;
        
        CGPoint point = CGPointMake(point_X, point_Y);
        
        // Record the coordinates of each point so that you can add gradient shadows and click on the layer view
        [pointArray addObject:[NSValue valueWithCGPoint:point]];
        
        if (i == 0) {
            [pAxisPath moveToPoint:point];
        }
        else{ [pAxisPath addLineToPoint:point]; }}CAShapeLayer *pAxisLayer = [CAShapeLayer layer];
    pAxisLayer.lineWidth = 1;
    pAxisLayer.strokeColor = [UIColor colorWithRed:255/255.0 green:69/255.0 blue:0/255.0 alpha:1].CGColor;
    pAxisLayer.fillColor = [UIColor clearColor].CGColor;
    pAxisLayer.path = pAxisPath.CGPath;
    [self.layer addSublayer:pAxisLayer];
}
Copy the code

Problems encountered (solved)

The reloadDatas method is invalid, the title hasn’t changed, the data source hasn’t changed, and when you remove the layer, it still blinks

Solution: When reloadData, you need to clear the cached array pointArray data, otherwise the array has the last data stored.

Reference: Code for a high level of appearance statistics – zhanfei

Parsing the interview

Edit: Normal University little Hatten

This section explains the knowledge of depth copy. This article will start with the difference between deep and shallow copy, and then explain the result of copying mutable and immutable objects in iOS, and how to make a true deep copy of collection objects. Finally, take you to achieve the depth of the custom object copy.

Understanding of depth copy

We first need to understand the purpose of copying: to create a copy object that does not affect the source object.

Deep copy and shallow copy

Copy type Copy the way The characteristics of
Deep copy Memory copy, with the copy object pointer and the source object pointer pointing toTwo pieces ofMemory space with the same content. 1. The reference count of the copied object is not increased.

2. A memory allocation is generated and two pieces of memory appear.
Shallow copy Pointer copy: a copy of a memory address to which the copy object pointer and the source object pointer pointWith a piece ofMemory space. 1. The reference count of the copied object is increased.

2. No new memory is allocated.

Note: If it is a small object such as NSString, it may passTagged PointerTo store, no reference count.

In short:

  • Deep copy: A memory copy that generates new objects without increasing the reference count of the copied objects
  • Shallow copy: A pointer copy does not generate new objects. Adding the reference count of copied objects is equivalent to a retain
  • Differences: 1. Whether reference counting is affected. 2. Check whether new memory space is created

The result of copy and mutable copy of mutable and immutable objects in iOS

IOS provides two copying methods:

  • Copy: immutable copy is produced
  • MutableCopy: mutableCopy

Copy mutableCopy to mutable and immutable objects

Source object type Copy the way Replica object type Copy Type (Deep/shallow)
Mutable object copy immutable Deep copy
Mutable object mutableCopy variable Deep copy
Immutable object copy immutable Shallow copy
Immutable object mutableCopy variable Deep copy

Note: Immutable objects are defined as system classes NSArray, NSDictionary, NSSet, NSString, NSData and their mutable versions such as NSMutableArray.

One memory technique is that copying an immutable object is shallow; all other cases are deep.

We can also deepen our understanding according to the purpose of copying:

  • The operation of copying immutable objects produces immutable objects. Because the source object and the replica object are immutable, the pointer is copied to save memory
  • A mutableCopy operation on an immutable object produces a mutable object. The object type is different, so deep copy is required
  • The operation to copy a mutable object produces an immutable object. The object type is different, so a deep copy is required
  • To mutableCopy operation, generates a mutable object, in order to achieve the purpose of modifying the source object or the copy object does not affect each other, deep copy is required

The use of copy, mutableCopy to make a shallow or deep copy of a collection object is for the collection object itself

Use copy, mutableCopy to the collection object (Array, Dictionary, Set) for shallow copy is for the collection object itself, the default for the objects in the collection is shallow copy. That is, only the collection objects themselves are copied, not the data in them. The main reason is that not all objects in a collection can be copied, and the caller may not want to copy every object in the collection at the same time.

If you want to deep copy the collection objects themselves as well as the contents of the collection, you can use a method similar to the following: copyItems passes YES. However, it should be noted that all objects in the collection must comply with the NSCopying protocol, otherwise Crash will occur.

NSArray *deepCopyArray = [[NSArray alloc]initWithArray:someArray copyItems:YES];
Copy the code

Note: the initWithArray:copyItems: method does not in all cases deep copy the collection object itself. If you run [[NSArray alloc]initWithArray:@[] copyItems:aBoolValue]; If the source object is an immutable, empty array, then a shallow copy of the source object itself is performed. Apple uses the share element for @[].

However, if the copy of the objects in the collection is a shallow copy, then the collection is not really a deep copy. For example, if you need a true deep copy of an NSArray

object, then the inner array and its contents should also be deep copied. You can archive and unfile the collection objects, as long as the objects in the collection conform to the NSCoding protocol. In addition, in this way, no matter how many layers of the model objects stored in the collection are nested, deep copy can be realized, but the precondition is that the nested sub-models also comply with the NSCoding protocol, otherwise Crash will occur.

NSArray *trueDeepCopyArray = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:oldArray]];
Copy the code

Note that when initWithArray:copyItems: is used and copyItems are passed to YES, the objects in the generated replica collection object (the next level) are immutable, and all the deeper levels have their previous variability. For example, the following code will Crash.

NSArray *oldArray = @[@[].mutableCopy];
NSArray *deepCopyArray = [[NSArray alloc] initWithArray:oldArray copyItems:YES];
NSMutableArray *mArray = deepCopyArray[0]; // deepCopyArray[0] has been deeply copied as an NSArray object
[mArray addObject:@ ""]; // Crash
Copy the code

The way the collection is archived preserves all levels of variability, just as it was before.

Implement a copy of the custom object

If you want to copy custom objects, you need to follow the NSCopying protocol and implement the copyWithZone: method.

  • If I want a shallow copy,copyWithZone:Method returns the current object: return self;
  • If I want a deep copy,copyWithZone:Method creates a new object, assigns a value to the property you want to copy, and returns it. If there are nested submodels that also need deep copies, then the submodels also need to conform to the NSCopying protocol and call the copy method of the submodels when assigning attributes, and so on.

If the custom object supports mutable copy and immutable copy, you also need to comply with the NSMutableCopying protocol and implement the mutableCopyWithZone: method to return mutable copy. The copyWithZone: method returns an immutable copy. The user can make an immutable or mutableCopy by calling the copy or mutableCopy method on the object as needed.

What happens to the following code?

@interface Model : NSObject
@property (nonatomic.copy) NSMutableArray *array;
@end
Copy the code

It doesn’t matter if it’s an NSMutableArray or an NSArray object, it’s an NSArray object (deep copy). Since the property is declared as NSMutableArray, it is inevitable that some callers will call its add object, remove object and other methods. In this case, because the result of copy is an NSArray object, Crash will occur.

Reference: iOS Interview Parsing – understanding of depth copy

Good blog

King Pilaf is here

This topic: Package size optimization

1, Toutiao iOS installation package size optimization — new phase, new practice — from the wechat official account: Bytedance Technical team

In many channels recommended for many times the old article, again recommended or hope to open ideas with you together, especially in the binary file control, there are still a lot of more in-depth means to optimize, the optimization of resources may not be all means.

2, Toutiao optimization practice: iOS package size binary optimization, a line of code to reduce the download size of 60 MB — from the wechat official account: Bytedance technical team

The sister of the last article, but also more familiar with the article. All in all, segment migration is effective, but it brings other problems, such as the log parsing problem mentioned in this article. We also encountered a variety of small problems in the practice process, some binary analysis tools will fail, need to be adapted for segment migration IPA.

3. Useless Class Detection based on Mach-O + Disassembly

I rarely recommend my own articles in weekly newspapers, especially my old articles from 2 years ago. I recommend this article because I have listed the packet size ratio analysis for 58 lines of business. We can see from the data after years of package size governance, resource optimization space is not large, can only start from the binary file thin. Many companies’ apps may also have the same problem, that is, the thin resources have no too much space, then we should look for a breakthrough from the binary level. Address: Github WBBlades

Exploration and practice on the governance of Flutter package size — from meituan technical team: Yandong Zongwenhuichao

Talk about something new. The authors first analyzed the package size of the Flutter and selected different optimization schemes for the two platforms. On the Android platform, dynamic delivery is selected, while on the iOS platform, part of non-command data is dynamically delivered. The data and text segments were split by modifying the compilation back end of the Flutter to redirect the data into the file. The team that uses Flutter can take a look at this solution.

5. IOS optimization – Slim down – from wechat official account: CoderStar

This article introduces the techniques and solutions of APP slimming in detail, including resources and code levels. Image compression and code compilation options are explained in depth. The scheme is comprehensive. You can check whether there are any other schemes for APP slimming that have not been applied through this article.

6. Kopp: Why is iOS APP several times larger than Android APP? The flowers have opened in the warm spring

The previous several articles have introduced the technology of thin body more perfect. Here’s the answer to the question bosses often ask: Why is iOS pack bigger than Android? Is it because iOS technology is inferior to Android? I suggest all iOS programmers take a look at this question, at least to satisfy our own curiosity.

Learning materials

By Mimosa

Better Explaine

Address: betterexplained.com/

Better Explaine is a site that helps you really understand math concepts and make them interesting, where you can see many complex concepts broken down into figures, formulas and easy to understand explanations. The guiding principle is Einstein’s quote: “If you can’t explain it simply, you don’t understand it well enough.” There’s no poser, no stuffy teacher, just an excited friend sharing exactly what makes an idea come true!

Programmers may be recommended on a must-read list

Address: draveness. Me / / books – 1

Programmer books from DraP, this is the first in a series of books, and there should be more to come. In this recommendation, three “tomes” are recommended: SICP, CTMCP and DDIA. Even if you find these books as hard to read as I do (wry smile) and aren’t ready to read them, you can get a glimpse of what other people’s programming world is like from DraP’s book list recommendations 😉.

Tools recommended

Edit: CoderStar

Snipaste

Address: zh.snipaste.com/

Software status: The regular version is free, the professional version is charged, there are two versions of Mac and Windows

Software Introduction:

Snipaste is a simple but powerful screenshot tool that lets you paste your screenshot back to the screen as well! Ordinary version of the function is enough to use, I think it is the best screenshot software! (Below is the official picture)

LSUnusedResources

Address: github.com/tinymind/LS…

Software status: Free

Software Introduction:

A Mac application for finding unused images and resources in Xcode projects can help us optimize the package size.

About us

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

Phase to recommend

The 19th issue of iOS Fish Week

IOS Fish Weekly issue 18

IOS Fish Weekly issue 17

IOS Fish Weekly issue 16