1. #importwith#include, what is the difference between @class? #import<>with#import ""What's the difference?
1> #import and #include can contain the contents of a file completely,#import prevents the same file from being included multiple times
The 2> @class simply declares a class name and does not contain a complete declaration of the class ; @class can also solve the problem of loop containment
3> #import <> used to include the file that comes with the system,#import "" To include the custom file
2. PropertiesReadWrite,ReadOnly,Assign,retain,Copy,nonatomic,Atomic,Strong,WeakWhat is the role of each, in that case?
1> ReadWrite: Simultaneous generation of both the get method and the set method declaration and implementation
2> readonly: Generate declarations and implementations of Get methods only
3> Assign: The implementation of the Set method is a direct assignment for the basic data type
4> retain: The implementation of the Set method is the release old value,retain new value, for OC Object Type
5> copy: The implementation of the Set method is the release old value,copy new value, for nsstring,block and other types
6> nonatomic: Non-atomic, The implementation of the set method is not locked (higher than atomic performance)
7> Atomic: Atomic, thread-safe, set method implementation lock .
8> Strong: The object referenced by a strong pointer, the system does not automatically release
9> weak: An object referenced by a weak pointer, the system immediately releases
Summary of @property parameters used in ARC:
1> control with weak equivalent to MRC assign
The 2> Property Object is strong(for example,nsarray *datalist) equivalent to the MRC retain
3> Non-object type with assign equivalent to MRC assign
4> string nsstring with copy equivalent to MRC copy
3. Write aSettermethod is used to complete@property(Nonatomic,retain)NSString *name,Write aSettermethod is used to complete@property(nonatomic,Copy)NSString *name.
1> @property (nonatomic, retain) NSString *name;
-(void) SetName: (NSString *) name
{
if (_name! = name) {
[_name release];
_name = [name retain];
}
}
2> @property (nonatomic, copy) NSString *name;
-(void) SetName: (NSString *) name
{
if (_name! = name) {
[_name release];
_name = [name copy];
}
}
4. For statementsnsstring*obj = [[NSData alloc] init];, compile-time and run-timeobjWhat are the different types?
1> compile-time is nsstring type
2> Runtime is nsdata type
5. Commonobject-cThe data types have those, andCWhat is the difference between the basic data types?
1> commonly used OC types:nsstring,nsarray,nsdictionary, nsdata,nsnumber , etc.
2> OC objects need to manage memory manually,C 's basic data type does not need to manage memory
6. IdDeclaration ofWhat are the characteristics of a variable?
the variables declared by ID have run-time attributes. ID the declared variable can point to any OC Object
5.2 Instancetype & ID
1> instancetype on A type representation, as with an ID , can represent any object type
2> Instancetype can only be used on return value types and cannot be used as an ID on parameter types
One benefit of 3> instancetype than ID : The compiler detects The True type of instancetype
7. Objective-cHow to manage the memory,tell me what you think and how to solve it.?
1> Each object has a reference counter, the counter for each new object is 1, and when the object's counter is reduced to 0 , it is destroyed
2> by retain can let the object counter +1,release can let the object counter -1
3> can also manage memory through autorelease pool
4> if ARCis used, the compiler automatically generates code to manage memory. The compiler will automatically insert the appropriate retain,release, andautorelease statements where appropriate. You no longer need to worry about memory management , because the compiler handles everything for you. ARC is not a GC, it is just a code staticAnalyzertool.
8. What are the several principles of memory management? Follow the default rules.Which methods generate objects that need to be released manually? In and Propertyhow to effectively avoid memory leaks when combined?
1> who created who was released. Whenever a alloc,copy, New method is called to produce a new object, it must be called at the last release or autorelease
2> who retain who release. Whenever retainis called, either release or autorelease must be called at the end .
3> @property If you use copy or retain, you need to do a release for the attributes that you no longer use . Operation
4> if ARCis used, the compiler automatically generates code to manage memory
1. See the procedure below,Three plays NSLogwhat does it output? Why?
nsmutablearray* ary = [[Nsmutablearray array] retain];
NSString *str = [nsstring stringwithformat:@ "test"]; 1
[Str retain]; 2
[Ary Addobject:str]; 3
NSLog (@ "%d", [str retaincount]);
[Str retain]; 4
[STR release]; 3
[STR release]; 2
NSLog (@ "%d", [str retaincount]);
[Ary Removeallobjects]; 1
NSLog (@ "%d", [str retaincount]);
Results:3,2,1
2. OCwhat is the method for creating threads in? IfSpecify to execute code in the main thread? How to delay code execution?
1> Ways to create threads
- Nsthread
- Nsoperationqueue and nsoperation
- GCD
2> executing code in the main thread
- [Self performSelectorOnMainThread:withObject:waitUntilDone:];
- [Self performselector:onthread:[nsthread mainthread] Withobject:waituntildone:];
- Dispatch_async (Dispatch_get_main_queue (), ^{
});
3> Delay execution
- Double delayinseconds = 2.0;
dispatch_time_t poptime = Dispatch_time (Dispatch_time_now,
(int64_t) (Delayinseconds * nsec_per_sec));
Dispatch_after (Poptime, Dispatch_get_main_queue (), ^ (void) {
});
- [Self performSelector:withObject:afterDelay:];
- [Nstimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:];
iOS pen question 01