Objective-c related to the iOS Test series

Source: Internet
Author: User
Tags gcd shallow copy tmp file tmp folder

1. Describe the design patterns commonly used in your project. What are their pros and cons?

The common design patterns are: agents, observers, and Singleton.

(1) Singleton: It is used to restrict the creation of a class to only one object. The properties in this object can store the globally shared data. All classes can access and set the attribute data in this singleton.

Pros: Yes it only creates an object that is easy for outside access and saves performance.

Disadvantage: A class has only one object, which may lead to excessive liability, and to a certain extent violates the "single responsibility Principle". There is no abstraction layer in the singleton pattern, so the expansion of the Singleton class is very difficult. You cannot create a single case too much because the singleton will persist until the program is closed, and too many single instances can affect performance and waste system resources.

(2) Observer (KVO): It provides a way to observe a change in a property. When the property of the specified object changes, it automatically notifies the appropriate observer.

Advantage: can provide the new value and the old value of the observed attribute. Use keypaths to observe attributes, so you can also observe nested objects.

Cons: Need to register observer, implement Observevalueforkeypath: Method, attribute must be modified by KVC method. Otherwise the observer cannot receive the notification.

(3) Proxy: You can implement one-to-one communication between classes and classes.

Advantages: The proxy protocol approach is clearly defined. The proxy method can be set optional or must be implemented.

Disadvantage: Need to define protocol method, need to set proxy object, proxy object implement protocol method. For memory management, you need to be aware of circular reference issues.

2, Agent mode can realize a one-to-many communication?

Yes, it can be implemented by means of multicast delegation. Multicast delegate: It is the ability to allow the creation of a call list of methods or linked lists. When a multicast delegate is called, the methods in the list are automatically executed.

Normal agent can only be one-to-one callback, unable to do a pair of callbacks, and multicast delegation formally to the delegate extension and extension, a more registration and cancellation process. Any object that needs a callback must be registered first.

3. Is there a problem with repeating the registration notice?

There is no problem, and if you send the same notification multiple times, the other person will respond multiple times. If you repeatedly sign up for notifications, you will also have the effect of multiple responses. To avoid errors caused by duplicate registration notifications, it is recommended that you remove the notification one time before registering a notification.

4. Have you used multithreaded programming in your project? Describe your commonly used multi-threaded implementation method?

Commonly used is the GCD.

GCD is a multi-core programming solution for Apple development. The GCD queue is divided into two types, serialdispatchqueue and Concurrentdispatchqueue. The system provides a dispatch_get_main_queue, a dispatch_get_global_queue by default.

5, briefly describe the difference between nsoperationqueue and GCD.

(1) GCD is the underlying C-language API. Nsoperationqueue and related objects are OBJC objects. In GCD, a block-composed task is executed in the queue, which is a lightweight data structure. And operation as an object gives us more choices.

(2) In Nsoperationqueue, we can cancel the task, and GCD cannot stop the block that has joined the queue.

(3) Nsoperation can easily set up the dependency relationship. The priority of the nsoperation can also be set, allowing tasks in the same parallel queue to be executed in a separate sequence. In GCD, we can only differentiate between the priorities of different task queues, and it requires a lot of complex code to differentiate between block task priorities.
Nsoperation can also set the number of concurrent numbers.

6. What are the different ways to implement multithreading?

(1) Nsthread:detachnewthreadselector:

(2) Succession nsoperation

(3) Gcd:dispatch_async

(4) Nsobject:performselectorinbackground:

7. What is KVC and kvo? The realization principle of KVO is briefly described. KVO can I listen to an array? How is it implemented?

KVC: Key-value encoding, which is an indirect access to an object instance variable mechanism that can access an object's instance variables without accessing the method.

KVO: A key-value observation that enables an object to get notification mechanisms for changes in other object properties.

Key-value coding and key-value observations are based on isa-swizzling technology, based on the powerful dynamic capabilities of the runtime. When a KVO listener is added to an object for the first time, the runtime dynamically creates a derived class of the Listener object, and then overrides the setter method that KVO needs to listen for the property value, and implements the notification mechanism in this setter method. Finally, the listener object's Isa points to the dynamically created derived class. This allows the corresponding setter method in the dynamically created derived class to trigger the notification mechanism when the property value is modified using KVC, thus implementing the KVO.
KVO can listen to an array.

To implement the nsmutablearray of adding and deleting to the KVC rules, the corresponding method needs to be implemented:

Add Operation-insertobject:inatindex: or-insert:atindexes:

Delete operation-removeobjectfromatindex: or-removeatindexes:

Change operation-replaceobjectinatindex:withobject: or-replaceatindexes:with:

These interfaces are exposed to the caller, and the interfaces implemented above are used to operate on the array.

8. What is the difference between these languages in simple c++,java,objective-c?

Both Objective-c and Java are single-inheritance languages, and C + + is a multiple-inheritance language.

Objective-c does not support namespace mechanisms, which are distinguished by prefixing the class name with NS.

Operator overloading is not supported for Objective-c and Java.

The OBJECTIVE-C protocol is optional, and the Java interface must be implemented.

9. Is there a problem with adding nil elements to an array? Can the Dictionary object and key be set to nil?

There will be problems with adding nil elements to the array and the program will crash! Quoted object cannot be nil error. The dictionary key cannot be nil, or it will cause a crash. The object of the dictionary cannot be nil either.

10. Is there a problem sending messages to a nil object in OC?

The problem does not occur because OBJC is a dynamic language, and each method is dynamically converted to a message when it is run. namely: Objc_msgsend (Receiver,selector). OBJC when sending a message to an object, the runtime library finds the class that the object actually belongs to, based on the object's ISA pointer, then looks for the method in the list of methods in the class and its parent class method, and then when the message is sent, the Objc_msgsend method does not return a value. The so-called return content is executed at the time of the specific invocation. So, back to the point, if you send a message to a nil object, the first time you look for the object's ISA pointer is the 0 address returned, so there is no error.

11. is a mutable array thread-safe? Under what circumstances is it unsafe? Can I lock it? Is it locked to add element operations or array objects?

Variable groups are not thread-safe and are unsafe in the case of asynchronous read data. You can lock and lock the array.

12. Can the array add a block? Array add a block and then remove it, is this block useful?

Yes, it's also useful, it's just more retain once.

13, Nsmutabledictionary in the Setobject:forkey: and Setvalue:forkey: What is the difference between the method?

Setobject:forkey: The value is not nil, or it will be an error.

Setvalue:forkey: value in can be nil, but when value is nil, the Removeobject:forkey method is called automatically.

Setvalue:forkey: The parameter in the key can only be nsstring type, and Setobject:forkey can be any type.

14, briefly describe the difference between copy and mutablecopy.

(1) Non-container objects:

For immutable objects: Copy is a pointer copy (shallow copy), and Mutablecopy is an object copy (deep copy).
For mutable objects: Copy and Mutablecopy are object copies.

(2) Container object:

For immutable objects: Copy is a pointer copy, and mutablecopy is an object copy.

For mutable objects: Copy and Mutablecopy are object-copied, except that the object type returned is not the same, which returns an immutable object, which returns a Mutable object.

Container object replication is limited to the object itself, and the object element is still a pointer copy.

15, briefly describe the difference between weak and assign.

Weak is used to modify objects and not to modify basic data types. Assign are generally used to modify basic data types. The weak modifies the object to set the object to nil after it is disposed.

16. Under Arc, what are the default keywords when no attribute keywords are specified?

Basic data type default modifier keyword: atomic,readwrite,assign

Normal OC object default modifier keyword: atomic,readwrite,strong

17. When is weak empty?

Runtime on the registered class, will be laid out, for the weak object will be placed in a hash table. Use weak point to the object memory address as key, when the reference count of this object is 0 will be dealloc, if weak point to the object memory address is a, then will be a key, in this weak table search, find all the A-key weak object, and set to nil.

We can design a function (pseudo-code) to represent the above mechanism:

Objc_storeweak (&a, b) function:

The Objc_storeweak function takes the memory address of the second parameter – the assignment object (b) as the key value key, and registers the memory address (&A) of the first parameter –weak the Decorated property variable (a) as value in the weak table. If the second parameter (b) is 0 (nil), then the memory address (&a) of the variable (a) is removed from the weak table.
You can interpret Objc_storeweak (&a, B) as: Objc_storeweak (value, key), and when key becomes nil, the value is nil.

When B is non-nil, A and B point to the same memory address, and a becomes nil when B becomes nil. Sending a message to a does not crash: sending a message to nil in objective-c is safe.

And if A is modified by assign, then: When B is non-nil, A and B point to the same memory address, and when B is nil, a still points to the memory address, and the variable field pointer. Sending a message to a at this point is extremely prone to crashes.

Below we will use pseudo-code to simulate "how the runtime implements weak properties" based on the Objc_storeweak (&a, b) function:

Using pseudo-code simulations: How runtime implements weak properties
ID obj1;
Objc_initweak (&obj1, obj);
/obj reference count becomes 0, variable scope ends /
Objc_destroyweak (&OBJ1);

Below are explanations of the two methods used Objc_initweak and Objc_destroyweak:

In general, the function is to initialize the variable (OBJ1) with the weak modifier through the Objc_initweak function, releasing the variable (OBJ1) through the Objc_destoryweak function at the end of the variable scope.

The following describes the internal implementation of the method:

The implementation of the Objc_initweak function is this: when the variable with the weak modifier (OBJ1) is initialized to 0 (nil), the "Assignment Object" (obj) is used as a parameter to invoke the Objc_storeweak function.
obj1 = 0;
Obj_storeweak (&obj1, obj);

Other words:
Weak decorated pointer default value is nil (sending messages to nil in objective-c is safe)
The Obj_destroyweak function then takes 0 (nil) as a parameter, calling the Objc_storeweak function.
Objc_storeweak (&obj1, 0);
The preceding source code is the same as the following sources.

Using pseudo-code simulations: How runtime implements weak properties
ID obj1;
obj1 = 0;
Objc_storeweak (&obj1, obj);
/* ... the reference count of obj becomes 0 and is set to nil ... */
Objc_storeweak (&obj1, 0);

The Objc_storeweak function registers the memory address of the second parameter-the Assignment object (obj) as the key value, and the memory address of the first parameter –weak the Decorated property variable (obj1) into the weak table. If the second parameter (obj) is 0 (nil), then the address of the variable (obj1) is removed from the weak table, which is explained later in the related topic.

The above contents are summarized as follows:

(1) Get the address of the discarded object from the weak table as a record of the key value

(2) Assign a value of nil to all addresses enclosed in the record with the __weak modifier variable

(3) Delete the record from the weak table

(4) Delete the address of the discarded object from the reference count table as the record of the key value.

18. Has the automatic release tank been used? When is it released? What happens when an object is added to the auto-free pool and which auto-free pool does it join?

The main thread turns on Runloop by default, and Runloop automatically creates a Autoreleasepool,autorelease object that is automatically added to Autoreleasepool and empties the auto-free pool once runloop. Decorated with __autoreleasing modifiers, or class method creation will automatically join Autoreleasepool. It will be added to the nearest autoreleasepool.

19. Do you know what data persistence means in iOS? Please give a brief explanation.

Data persistence in iOS is as follows: SQLite3 database, CoreData, file archive, attribute list (plist file write).

Attribute list: The main class involved is nsuserdefaults, which stores a small amount of data.

File archiving: Objects must implement the Nscoding protocol. Implement Initwithcoder: Methods and Encodewithcoder methods. It is also recommended to implement the Nscopying protocol.

SQLite3 database: SQLite is an open source, embedded relational database. Portability is good, easy to use and requires little memory overhead. Suitable for embedded devices.

CoreData: It can use SQLite to save data, and does not need to write SQL statements. In addition, it can save data using XML. To use CoreData, you need to design individual entities and define their properties and relationships in the data Model Editor in Xcode. The persistence of data is accomplished by manipulating these objects.

20. Do you support multithreading in Fmdb? How it is implemented!

Support Multithreading. It has a fmdatabasequeue class inside it. It seems to be a queue, in fact it is not itself, it inherits NSObject, through the internal creation of a serial dipatch_queue_t to deal with Indatabase and intransaction incoming block, So when we call indatabase or intransaction in the main thread (or in the background), the code is actually synchronous. Fmdatabasequeue is designed to avoid thread-safety problems with concurrent access to the database, and all database accesses are performed synchronously, with greater efficiency than @synchronized and Nslock.

21. Describe the difference between category and extension. Category and the timing of extension loading.

You can only add methods to the category, and you cannot add instance variables (you can add attributes). Extension can not only increase the method, but also increase the instance variable or property (private). Extension does not have an independent implementation part like category. The category is determined at run time. Extension is a compile-time decision.

22. Can the category method inherit the quilt class? After overwriting the method of the original class, can the method of the original class be called? If you can, you explain why.

The category method can be inherited by the quilt class. Category is not an absolute override of the same name method of the class, but the category method is ranked before the method of the same name of the class, the method is retrieved sequentially, so when the method is called, the method called with the same name is the category, resulting in an overlay.
Using the run-time traversal method list, you can call methods that are overridden by category.

23. How to extend a class by inheriting good or category? Please explain why.

Use a good class of items. Because inheritance also needs to define subclasses. Classes do not need to add methods to existing classes by creating subclasses. The method of rewriting a class by category is only valid for this category and does not affect the relationship of other classes to the original class.

24. How many types of block are there? The implementation of block?

Block is divided into three types:

_nsconcreteglobalblock

_nsconcretestackblock

_nsconcretemallocblock

Block: anonymous function

25. Does swift use much? Simply say the difference between 1.0 and 2.0.

Swift2.0 added: Guard Statement, exception handling, Protocol extension, print statement change, avaliable check, do-while statement rename: Repeat-while,defer keyword

26. Have you used defer keywords in swift?

The delay to the defer statement, called at the end of the function.

27. Where is the picture of Sdwebimage saved?

The picture is saved under the Library/caches folder in the sandbox.

28. Why can't I add an instance variable to the Objective-c category?

Because the memory layout of an object is determined at run time, adding an instance variable destroys the internal layout of the class.

29, the Objective-c in the default is @optional or @require? What issues should you pay attention to when using the agreement?

The protocol in OBJECTIVE-C is the @require that must be implemented, the use of the Protocol should pay attention to circular reference problems, multiple protocols are separated by commas.

30. What is the difference between the OBJECTIVE-C protocol and the interface in Java?

The protocols in OC are optional, and the interfaces in Java must be implemented.

31. What are the application scenarios of the class purpose?

(1) The implementation of the class can be separated into several different files

(2) Declaring private methods

(3) Simulation multiple inheritance

(4) Exposing private methods of the framework

32. What is the difference between self and super?

Super is essentially a compiler identifier, and self is pointing to the same message receiver, the difference being that super tells the compiler to call the class method when it goes to the parent method, not the method.

33. Why does the picture cache not be saved to the TMP file directory under the sandbox?

Because the TMP folder is used to hold temporary files, itunes does not back up and restore this directory, and files in this directory may be deleted after the app exits.

34, Nsurlconnection and Nsurlsession.

Nsurlconnection It is an abstraction above the API of the Corefoundation/cfnetwork framework.

Nsurlconnection this name actually refers to a series of associated components in the URL loading system of the foundation framework: Nsurlrequest, Nsurlresponse, Nsurlprotocol, Nsurlcache, Nshttpcookiestorage, Nsurlcredentialstorage, and class nsurlconnection of the same name. Nsurlrequest was passed to Nsurlconnection. The delegate object (which adheres to the previous informal protocol and) asynchronously returns a Nsurlresponse and a nsdata that contains the information returned by the server.

Nsurlsession include: Nsurlrequest, Nsurlcache, Nsurlsession, Nsurlsessionconfiguration, Nsurlsessiondatatask, Nsurlsessionuploadtask, Nsurlsessiondownloadtask.
The difference between it and nsurlconnection is that the most immediate improvement of nsurlsession is the ability to configure caching, protocols, cookies, and formal policies for each session. This information is even shared across programs. Each Nsurlsession object is initialized by a Nsurlsessionconfiguration object.
Session Task: Handles the loading of data and the last and downloaded files and data between the client and the server.

35, briefly describe the difference between arc and MRC.

ARC: Auto reference count. MRC: Manual reference count. ARC is to give the memory to the system management. The system will automatically insert the retain/release at compile time. The MRC needs to manually manage the object's reference count. When you alloc,new,copy,mutablecopy or retain an object, you are obligated to send a release or autorelease message to it.

36. Briefly describe the principle of arc implementation. At what time does it insert retain/release?

ARC: Auto reference count. It automatically inserts retain/release when the object is created or dies. Achieve the purpose of automatically managing memory.

37. What is the difference between the framework and the library? What is the difference between a dynamic library and a static library?

The difference between the library and the framework:

In iOS, the Library can only contain compiled code, which is the. a file.
In general, however, a complete module may contain not only code, but also the. nib view file, picture resource file, and description document. (like the libraries provided by Umeng, when it comes to integrating a bunch of files into Xcode, it's not a hassle to configure them.)
The Framework, as a resource-wrapping method used in Cocoa/cocoa Touch, can be packaged together to make it easier for developers to use (like bundles).

The difference between a static library and a dynamic library:

Simply put, a static link library refers to a module being compiled and merged into an application, the application itself is larger, but no longer relies on third-party libraries. When you run multiple apps that contain the library, there will be more than one copy of the library in memory and redundant.
Dynamic libraries can be published separately, found and loaded into memory at run time, and can be shared if there is a common library, saving space and memory. The library can also be upgraded either directly or as a plugin.

38. What is Runloop?

In general, a thread can only perform one task at a time, and the thread exits after execution completes, if we need a mechanism that allows the thread to handle the event at any time but does not exit. The code logic is as follows:

function loop() {        initialize();        do {    var message = get_next_message();    while(message != quit)}

This model is commonly referred to as EventLoop (event loop). Runloop is actually an object that manages the events and messages that it needs to handle. and provides an entry function to perform the above eventloop logic. In the Osx/ios system, two such objects are available: Nsrunloop and Cfrunloopref.

Cfrunloopref is within the corefoundation framework, which provides APIs for pure C functions, all of which are thread-safe.

Nsrunloop is a cfrunloopref-based package that provides an object-oriented API that is not thread-safe.

Apple does not allow the creation of Runloop directly, only provides two automatically acquired functions: Cfrunloopgetmain () and Cfrunloopgetcurrent ().

The thread and the Runloop are one by one corresponding to each other.

39, #include与 the difference between #import? What is the difference between #import与 @class?

The #include is the same as the #import feature, which is the export header file. Just #import does not cause cross-compilation, you can ensure that the header file is imported only once. #import会包含这个类的所有信息. Includes instance variables and methods, and @class just tells the compiler that the name that is declared after it is the name of the class, and that the definition of the class will tell you later. Compiling with #import is efficient and prevents compilation errors that are included with each other.

40. What is the difference between static and const?

The const represents read-only meaning and is used only in declarations.

Static generally has 2 functions, which specify scope and storage methods. For a local variable, static specifies that it is a static store, the initial value of each invocation is the value of the last call, and the storage space is not freed after the call ends.

For global variables, this variable is visible only in the current file if the scope of the file is scoped, and for the static function is also visible within the current module.

41. Describe the difference between a GET request and a POST request.

(1) Post requires explicit method get not required, and default is Get method, and get has cache, post is not cached

(2) The get parameter is placed after the URL, and the first parameter is used for stitching, and the back one starts with the second argument, until the last, if there are multiple, with & split; The parameters of the POST are placed inside the request body, and the first parameter is not used, followed from the second start, until finally, if there are multiple, with & split;

(3) Get is generally used to get data, post to the server to submit data to

(4) Get parameters are critical leaks in the address bar, unsafe; The parameters of post are hidden in the request body, relatively safe.

(5) The GET request has no request body, and the POST request has a request body.

(6) Get request submission data is subject to browser restrictions, 1k,post requests theoretically unlimited.

42. What happens in memory when attributes are modified with __block?

Why use weak to modify properties outside the block to break the loop, the block also needs to convert the properties to strong.

43, talk about the difference between block and function.

Blocks can be written in methods, and functions need to be written out of the method. Block can access local variables in the method.

44. Do you know runloop? How many modes does it have? A brief description of its application scenario.

Runloop mode:

Default:

Nsdefaultrunloopmode (Cocoa), Kcfrunloopdefaultmode (corefoundation)

Connection:

Nsconnectionreplymode

Modal:

Nsmodalpanelrunloopmode

Event Tracking:

Nseventtrackingrunloopmode

Common modes:

Nsrunloopcommonmodes (Cocoa), Kcfrunloopcommonmodes (corefoundation)

Application Scenarios:

(1) Use a port or a custom input source to communicate with other threads.

(2) using timers in Threads

(3) using any of the Performselector methods

(4) Keep the thread to perform a periodic task.

45. What are the version management tools you work with?

Git tools are used to version management.

46. Have you ever used a git tool? What common commands have been used?

Git init,git Add, git commit,git merge,git branch,git checkout,git pull,git Push, etc.

47. What types of animations are commonly used in coreanimation?

All animation classes of the core animation are inherited from the Caanimation class. Caanimationgroup Group animation, catransition transition animation, Cabasicanimation: Basic animation, Cakeyframeanimation Keyframe animation.

48, GCD system provides several queue?

Two kinds: dispatchserialqueue, dispatchconcurrentqueue.

49. What is the concept of binary search tree and the complexity of time?

O (N)

50. Weak self in block, is it necessary to add it at any time?

Not necessarily, can be added without adding. You can also break a circular reference by placing a block nil.

51, gcd the code executed in the Queue,main queue, must be in main thread?

Yes. Must be in main thread.

52. Have you encountered any problems in using the database? How to solve?

Experienced multi-threaded operation database read-write deadlock problem, using the rollback provided in Fmdb to solve

53. Briefly describe the sandbox mechanism in iOS.

The sandbox mechanism in iOS is a security system that specifies that an application can read files only in folders created for the app, and that it cannot access content elsewhere. All non-code files are saved in this place. Film, sound, attribute list and text files.

(1) Each application is in its own sandbox

(2) You can't go across your sandbox to access the contents of another application sandbox

(3) Applications that request or receive data outside of the application require permission authentication.

Sandbox directory structure This, because the application is in the sandbox (sandbox), the file read and write permissions are restricted, only a few directories to read and write files:

Documents: User data in the app can be placed here, itunes Backup and restore will include this directory

TMP: Store temporary files, itunes does not back up and restore this directory, files in this directory may be deleted after the app exits

Library: The default settings or other status information for the stored program.

Library/caches: Store cached files, itunes does not back up this directory, files in this directory will not be deleted in the app exit

54. Why should the string be modified with copy?

To prevent mutablestring from being inadvertently modified, nsmutablestring is a subclass of NSString. So nsstring pointers can hold nsmutablestring objects.

55. What is the difference between nonatomic and atomic?

Atomic is a thread-protection technique used by OBJECTIVE-C to prevent write operations from being read by another thread when it is not completed. resulting in data errors. This mechanism is very resource-intensive, so on the iphone this small mobile device, if not using the communication between multi-threaded programming. It is recommended to use nonatomic.

The default accessor is atomic, that is, in a multithreaded environment, the parsed accessor provides a secure access to the property, the return value obtained from the accessor, or the value set by the setting can be done at once, even if multithreading is accessing it, and if nonatomic is not specified, in the environment in which it manages memory , the parsed accessor retains and automatically releases the reserved value, and if Nonatomic is specified, the accessor simply returns a value.

56. What is the difference between @synthesize and @dynamic?

@synthesize: If you do not implement setter methods and getter methods manually, the compiler will automatically generate setter methods and getter methods for you.

@dynamic: The setter and Getter methods that tell the compiler properties are implemented by the user themselves and are not generated automatically. If a property is declared as @dynamic var and does not provide a setter and getter method, there will be no problem compiling if the program runs to Person.name = NewName; or newname= Person.name will cause the program to crash. Because "unrecognized selector sent to instance ..." This is dynamic binding.

57, @property (copy) Nsmutablearray *array; what's wrong with this code? If you have a brief explanation;

(1) When adding, deleting, or modifying elements within an array, the program crashes because it cannot find the corresponding method because copy is copying an immutable Nsarray object.

(2) The Nonatomic property modifier is not used, and the default is the atomic adornment, which can seriously affect performance.

58, NSString *str = @ "Hello world!" with nsstring *str = [[NSString alloc] initwithstring:@ "Hello world!"]; What is the difference in memory management?

In MRC, the former indicates that you do not hold this object, so you do not need to manually manage its memory. The latter means that you hold the string, and you need to manually manage the memory to release it.

59, for the statement nsstring*obj = [[NSData alloc] init]; What type of object is obj at compile time and run time?

Compile-time is a NSString type object, runtime NSData type Object
First, declaring Nsstring*testobject is telling the compiler that obj is a pointer to a Objective-c object, because no matter what type of object it points to, a pointer takes up a fixed amount of memory space, so it declares that any type of object is called, The resulting executable code is no different. This limits the nsstring just to tell the compiler, please check obj as a nsstring, if you call a non-nsstring method, will generate a warning, then you create a NSData object, and then save the object's memory address in obj. At run time, the memory space that obj points to is a NSData object. You can use obj as a NSData object.

60. What is the difference between Self.name=object and name=object in memory management?

The former sets the value by invoking the setter method, which is a normal assignment operation.

61. Why are there only "copy" features in the property declaration and no "Mutablecopy" features?

This is because when declaring the property as a "copy" feature, the system automatically determines whether to use copy (with retain) or mutablecopy based on receiver's characteristics.

62. What is the difference between ID and void* in objective-c? What is the difference between ID and instancetype? What is the difference between nil, NULL, and null?

The difference between ID and void* in objective-c:

An ID is a pointer to an OC class object that can be declared as a pointer to any class object, and when the ID is used in OC, the compiler assumes that you know which object the ID points to. Unlike void*, the void* compiler does not know or assume that it points to any type of pointer.

ID differs from Instancetype:

The ID returns the type of the ID, and Instancetype returns the type of the class in which it is located.

The same point is the same as the return type of the method.

Difference:

(1) Instancetype can return an object of the same type as the method's class, and the ID can only return an object of an unknown type.

(2) Instancetype can only be used as a return value, and the ID may be used as a parameter.

Nil, nil, null three differences:

Nil is a pointer to an object that does not exist (object null pointer). Nil is a pointer to a class that does not exist (a class null pointer). Null points to other types of null pointers. Nsnull the object that represents the null value in the collection object.

63. How many data parsing methods are there? What difference do they have? What kind of data parsing method do you use in your project?

JSON and XML.

64. Declare a constant with pre-processing directive # # to indicate how many seconds are in 1 years (ignoring leap year issues)

"#define Seconds_per_year (60*60*24*365) UL"

65, write a "standard" macro min, this macro input two parameters and return the smaller one.

"#define MIN (x x) > (y)? ( X):(Y)) "

66. What is the difference between +load and +initialize?

+initialize: Called before initializing this class for the first time, we use it to initialize static variables.

The +load method is called when the class is loaded, that is, when the iOS app is launched, all classes are loaded.

The +initialize method is similar to a lazy load, and if this class is not used, the system does not call this method by default and is loaded only once.

If the +load method is all executed in the category, but the Load method in the category is later than the method in the class, the +initialize method overrides the method in the class and executes only one.

The invocation of +initialize occurs before the +init method. The subclass will call the +initialize method of the parent class.

67. The difference between new and Alloc/init

In summary, new and alloc/init are functionally almost identical, allocating memory and completing initialization.
The difference is that the initialization can only be done with the default Init method in new mode.
The method of Alloc can be used in other custom initialization methods.

68, if let you design interface and API, should pay attention to what?

(1) Avoid namespace collisions with prefixes

(2) Provide "All-in-all initialization method"

(3) Implement Description method

(4) Use immutable objects as much as possible

(5) Use a clear and coordinated naming method

(6) Prefix the private method name

(7) Error handling

(8) Implement the Nscopying protocol.

69. Have you used lazy loading in your project? Can you simply say lazy loading?

Lazy loading is also known as deferred loading. is written with its get method. If it is lazy loading, you must pay attention to the first to determine if there is already, if not then to instantiate.

The advantage is that the code that creates the object is not written all in the Viewdidload method, and the code is more readable. Each control's Getter method is responsible for the respective instantiation, and the code is highly independent and loosely coupled.

70, process and thread of the difference and contact.

A process is a static container that accommodates many threads, which are linear execution paths for a series of methods.

71. Describe the memory partition situation.

Stack: The parameter value of the stored function, the value of the local variable, and so on. Automatically allocated by the compiler release

Heap area: Freed by programmer assignment. If the programmer does not release, the program may end up being reclaimed by the system

Global zones: Global variables and static variables are stored in a block. Initializes global variables and static variables in an area, uninitialized global variables, and uninitialized static variables in another area. Released by the system after the program is finished. The global zone can be divided into uninitialized global zones:. BBS segment and initialize Global zone: Data segment.

Constant zone: holds a constant string, released by the system after the program is finished

Code area: A binary code that holds the body of the function.

72. What is the difference between a queue and a stack?

Stack: a linear table that restricts insert or delete operations only at the end of a table. The footer is the top of the stack, and the table header is the bottom. It is also called the LIFO table.

Queue: is a FIFO linear table. It only allows insertion at one end of the table, and removes the element at the other end.

73, OBJECTIVE-C Multi-Threading programming method has several

Pthread, Nsthread, Nsoperation, GCD.

The resources are as follows:

(1) "Recruiting a reliable IOS"-reference answers (top)

(2) "Recruiting a reliable IOS"-reference answers (below)

Part of this article is from the network, the follow-up will be continuously updated and perfected. Welcome to learn to communicate together!

If you want to reprint, please specify the source

Objective-c related to the iOS Test series

Objective-c related to the iOS Test series

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.