What type of object obj is at compile time and runtime, respectively
As in the following code, obj what type of object is at compile time and runtime, respectively:
| 123 |
nsstring *obj = [[nsdata alloc] init]; |
Reference Answer:
At compile time, we declare the obj NSString * type and therefore the NSString type object. At run time, because the pointer obj is pointing to the memory of the NSData type object, it is actually an NSData object of type. At compile time, this line of code is converted to something like this:
| 1234 |
NSString*obj=((ID (*)(ID, SEL))objc_msgsend)([ NSData class], @selector(alloc)); Obj = ( (id (*) (id, sel) ) objc_ Msgsend (id< Span class= "Crayon-sy" >) obj, @selector (init |
Because at compile time, it id can be used to point to an NSString * NSData object, and it id has a run-time attribute, so at the time of the link, the passed id isa pointer can find the class to which it belongs, so the final type is isa determined by its owning type.
What are the attributes of an object declared by ID?
idA type can point to any type of object.
Reference Answer:
Let's look at the definition first:
| 123456789 |
// represents an instance of a class.struct objc_Object { Class Isa objc_isa_availability; };/ A pointer to an instance of a class.typedef struct objc_object *id; |
It can be defined id as a pointer to a objc_object struct type that has only one pointer to an object without a class, isa so id it can point to any type of object, so it has run-time characteristics.
iOS Device performance Testing
In practical development, we often need to thin the application, so the performance of the detection is very important.
Reference Answer:
Use Profile Instruments Time Profiler ----to detect performance.
Are there private methods, private variables in objective-c?
I remember once I was asked, do not know if you have met.
Reference Answer:
Declared within a class's .m implementation file, it can be used as a private method, as a private variable. However, not the absolute private, if the external know that there is such a method, the same can be called, and will not error. Just as Apple is not publicly API api available, it can be called as long as we know it in other ways. As a result, Apple often uses private to api call back when the audit.
16. Brief introduction to the reuse mechanism of TableView
I was also asked this question when I was interviewed by the author.
Reference Answer:
| 123 |
[[uitableviewcell alloc] initwithstyle: uitableviewcellstyledefault Reuseidentifier: Cellidentifier] |
- This method is the core of the reuse mechanism. For example, there is an interface that can display 10 cells, then create 10 cells and assign
cell the same reuse identity (of course, you can specify different identities for cells of different display types) and 10 cell will all be added to the visiableCells array, reusableTableCells empty.
- Scrolling
tableView , when there is a cell completely removed screen, this cell will be added to reusableTableCells . And the new one cell will be added visiableCells , and this cell is reused.
If you want to make tableview it non-reusable, do not set reuseIdentifier it.
The difference between nil and null
Reference Answer:
nilThe C same as the language NULL , objc/objc.h defined in. nilindicates that Objective-C the value of the object is empty. In the C language, the null value of the pointer is NULL represented. In Objective-C , the nil object calls any method that represents nothing and does not crash.
For more details, please read the author's article: http://www.henishuo.com/nil-nil-null-nsnull-difference/
What is the category and when is it used?
Reference Answer:
Categoryis the so-called extension.
Sometimes we need to add some methods to an already defined class, rather than rewrite the class, it's good to use the extension. For example, when the project is already large, the amount of code is greater, or there are already many methods in the class, other code has called the class to create the object and use the method of the class, you can use the class to expand the new method.
I go to the company, will be based on the company's UI style to customize a set of UI components, unified overall style. I always do not like xib/storyboard to use development, because the maintenance costs are too high. Can we not customize the various components in the way we inherit them? So this time using extensions is the best time.
19. What is delegate? Common scenarios?
Reference Answer:
Delegateis the so-called agent, Agent is a design pattern. In iOS development, a large number of proxies are used, while the proxy design pattern is the standard setting mode in Apple.
Common scenarios have a reverse pass value. For example: Apple Bluetooth, we go to the next interface to open or turn off Bluetooth, when the operation needs to feed back to the previous interface, and update the display. For this state, using the proxy design pattern is a very standard pattern.
20. What is a singleton and how to design a single case?
Reference Answer:
The Singleton is that only one object exists globally and is present throughout the App run. Each App will have a single case, for example UIApplication . When we do the user data storage, we usually use a singleton store, because the application in all operations, often require first login.
The following is the most commonly used notation, which is thread-safe.
| 12345678910111213 |
+ (instancetype)shared { static hybusermanager *sg_usermanager = nil; static dispatch_once_t oncetoken; dispatch_once(&oncetoken, ^{ if (sg_usermanager = = nil) { sg_usermanager = [[hybusermanager alloc] init]; } }); return sg_usermanager; } |
21. What is a notification?
Reference Answer:
In iOS , notifications are a very common design pattern. It is a many-to-many relationship. Regarding the notice, because this section is more important, writes an article separately, in my essay has the detailed explanation, the interest may go to look.
Written in the last
The article inevitably has to say unreasonable place, if you think the statement is incorrect or where there is the wrong place, please leave a comment in the comments, the author will be in the first time to amend!!!
iOS Basic Pen Questions-(2)