What are the property keywords readwrite, readonly, assign, retain, copy, and nonatomic used in that case?
1. Readwrite is a readable and writable feature. Getter and setter methods need to be generated. 2. Readonly is a read-only feature. Only getters are generated, not setters, and you don't want the property to change outside the class. 3. Assign is an assignment feature. Setter methods assign incoming arguments to instance variables; Assign is used for the base data type when only variables are set. 4. Retain (MRC)/ Strong (ARC) indicates the hold feature. Setter methods leave the passed argument and assign it, and the retaincount of the passed argument is +1. 5. Copy Indicates the copy feature. Setter methods make a copy of the passed object and require a complete copy of the new variable. Nonatomic operation. The default is atomic. The difference between atomic and nonatomic is that the getter/setter methods generated automatically are different. For atomic properties, system-generated getters/setters guarantee the integrity of get and set operations, whereas nonatomic properties do not. So nonatomic is faster than atomic.Copy the code
Atomic does not guarantee thread-safety, however.
What are the two parts of a complete class in OC
A class in an OC must have two parts, an interface part and a implementation part. OC puts the declarations of member variables and member methods in the Interface section, including inheritance relationships, protocal implementation relationships, all declared in the interface header, and then puts the implementation part in the implementation section. It's like splitting a class into declaration and implementation.Copy the code
Setter and getter methods for property
Setters provide an interface to the outside world to modify internal property values by sending this message to object Pointers (calling setter methods). A getter is an interface provided by the outside world to view an internal variable.Copy the code
Copy and mutableCopy
Deep copy:
Object copy - reapply a piece of memory to preserve the object, with no relation to the original object.Copy the code
Shallow copy:
Pointer copy - actually equivalent to reference count +1, copied and copied reference to the same object.Copy the code
1. Copy non-collection objects. NSString is used as an example
Copy an immutable object is a pointer copy, and mutableCopy is a copy of an object. Copy and mutableCopy are both copies of objects with the same memory address.Copy the code
2. Copy collection objects
Copying an immutable object is a pointer copy. Copying an immutable object is an incomplete deep copy. Copy or mutableCopy of a mutable object is an incomplete deep copy.Copy the code
What’s the difference between frame and bounds?
Frame refers to the position and size of the view in the parent view coordinate system. The reference point is the parent view's coordinate system. Bounds refers to the view's position and size in its own coordinate system. (Reference point is its own coordinate system)Copy the code
Can objective-C classes be multiple inherited? Can you implement multiple interfaces? What’s a Category? Is it better to inherit or categorize methods to rewrite a class? why
Objective-c classes can't be multiple inherited; Multiple interfaces (protocols) can be implemented; A Category is a Category; In general, the method of classifying and rewriting a class with a Category is only effective for this Category and does not affect the relationship between other classes and the original classCopy the code
When is the weak keyword used, and how is it different from assign
1. In ARC, when a circular reference is possible, it is usually resolved by having one end use weak, such as the delegate delegate attribute. 2. It has been strongly referenced once by itself, and there is no need to strongly reference it again. In this case, weak is also used. Of course, you can also use strong. Why can the view property connected by IBOutlet be set to weak? Because the parent control's subViews array already has a strong reference to it. Differences: Assign can be used with non-OC objects, while weak must be used with OC objects. Weak indicates that the property defines a non-ownership relationship. The property value is automatically cleared (nil) when the object to which the property refers is destroyed.Copy the code
Objective-c memory management
There are three main methods of memory management in Objective-C: ARC(Automatic memory counting), manual memory counting, and memory pools. 1. Automatic Memory counting ARC: Xcode automatically adds memory management code to the code during App compilation. 2. Manual memory count MRC: Follow the memory who apply, who release; The principle of who adds, who releases. 3. Release Pool: All memory that needs to be released is put into a Pool. When the Pool is drained, all memory space in the Pool is automatically released. The memory pool can be released automatically or manually. Automatic release is affected by the Runloop mechanism.Copy the code
The difference between Category, Extension, and inheritance
1. A class extension has no class name and is a special category. 2. Classes can only extend methods (attributes are only declared, not really implemented). Class extensions can extend attributes, member variables, and methods. Inheritance can add, modify, or delete methods, and can add attributes.Copy the code
ViewController life cycle
1. InitWithCoder: triggered when initialized by niB file. AwakeFromNib: When the NIB file is loaded, an awakeFromNib message is sent to each object in the NIB file. 3. LoadView: Starts to load the view of the view controller. 4. ViewDidLoad: The view controller's view is loaded. ViewWillAppear: The view controller's view will be displayed on the window. UpdateViewConstraints: The view of the view controller starts updating the AutoLayout constraint. ViewWillLayoutSubviews: The view controller's view will update the position of the content view. ViewDidLayoutSubviews: The view controller's view has updated the position of the view. ViewDidAppear: The view controller's view is displayed on the window. 10. ViewWillDisappear: The view controller's view will disappear from the window. ViewDidDisappear: The view controller's view disappears from the window.Copy the code
Kvo and KVC
kvc
Assign a value to an object's property via a key-value path. SetValue: ForKey: Obtains the value of the property through the key-value path. ValueforKey = valueforKey = valueforKeyCopy the code
kvo
KVO provides an observer mechanism by adding an observer to an attribute of an object. When the attribute changes, the "observeValueForKeyPath:" method is called, providing us with an "Object value changed!" Time to perform some operations.Copy the code
What is RunLoop and what does unloop do? What does runloop have to do with threads? Does the main thread have Runloop enabled by default? What about child threads?
A runloop is a do-while loop in which various tasks (such as Source, Timer, Observer) events are continuously processed. The relationship between runloops and threads: Each thread has one runloop. The runloop of the main thread is created and started by default, and the runloop of the child thread must be created and started manually (by calling the run method). Only one Mode can be selected to start the RunLoop. If there is no Source(Sources0, Sources1) or Timer in the current Mode, exit the RunLoop directly.Copy the code
What does the mode of runloop do? How many modes are there?
Model: Is the running mode of runloop. Different runloop modes handle different events and messages. KCFRunLoopDefaultMode: the default Mode of the App, under which the main thread is usually run. 2.UITrackingRunLoopMode: interface tracking Mode, used for ScrollView tracking touch sliding, to ensure that the interface sliding is not affected by other modes. 3. UIInitializationRunLoopMode: when just start the App the first to enter the first Mode, start after the completion of the will no longer be used. 4. GSEventReceiveRunLoopMode: accept system internal Mode of events, usually in less than. 5. Kcfrunloopcommonmode: This is a placeholder Mode and has no effect. Note that iOS encapsulates the model in the above 5 NSDefaultRunLoopMode and NSRunLoopCommonModesCopy the code
The logic in SDWebImage to load an image into UIImageView
SDWebImage for UIImageView classification provides a UIImageView + WebCache. H, this classification is one of the most commonly used interface sd_setImageWithURL: placeholderImage:, The placeholder image will be displayed before the real image, and replaced when the real image is loaded. The process of loading an image is generally as follows: 1. First, the SDWebImageCache will search for the corresponding cache of the image, and it will use the URL as the index of the data to search for the corresponding cache in the memory 2. If the cache is not found, it will use the KEY processed by MD5 to continue to query the corresponding data in the disk. If it is found, the data in the disk will be loaded into the memory, and the picture will be displayed 3. If none is found in memory or disk cache, a request is sent to the remote server to start downloading Picture 4. The downloaded image will be added to the cache and written to the disk. 5. The whole process of obtaining the image is executed in the sub-thread, and the image will be displayed back to the main thread after obtaining the image. Find the image in memory (dictionary) (when the image has been loaded during the use of the program) and use it directly. 2. Find the image in the sandbox (when the image was loaded during the previous use of the program), use it, and cache it in memory. 3. Get from the network, use, cache to memory, cache to sandbox.Copy the code