The purpose of writing this article is because two days ago, my classmate wanted to apply for iOS development, and asked me to help check the iOS interview questions and answers from the Internet. I glanced at it, gasped, and shivered with anger. None of the answers to more than 30 questions is correct. The author of the summary of this interview question dares to post on the Internet with a little knowledge of the iOS mechanism. Whether intentional or unintentional, it is a trap for new people. So here is a summary of these years interview others and others interview encountered some basic topics I think better to share with you, advanced topics in the follow-up supplement. If there is any mistake in my understanding, please be sure to point out. Thank you very much!

It has been three years since I started to work as an interviewer in 2012. During this period, I have met many developers from Tencent, Baidu, small companies, outsourcing companies, and those who have no code ability to do management. My impression is that Baidu has the best technical ability, with solid and confident grasp of basic knowledge and technical details. Tencent is also very good in technical details, which is worse than Baidu on average. However, it has strong ability to solve problems and active thinking. Students from small companies and outsourcing companies have poor technical details and basic knowledge. Personally, I am very opposed to the argument that the products of BAT must be better than those of other companies. I can only say that BAT provides a better technical atmosphere. You can work with more excellent people, and it is easier to make technological progress compared with small companies.

During this period I also face a lot of Internet company, tencent, baidu, ali, fast and many other small and medium-sized companies, give my feeling is China’s whole Internet the interviewer’s attitude is very bad, the interviewer often habitually late, reason to have a meeting, at dinner, the most ridiculous is that there is no any reason to let you in there, etc. In fact, I think these companies haven’t realized that the vast majority of developers just come to look at opportunities, not to apply for jobs, so they can’t find anyone. While talking about how desperate their company is for talent and how they don’t treat candidates with due respect. I think interview is a very bad word, the application process should be called interview, review is more appropriate, it is a two-way selection process.

I attended more than 50 interviews, only two interviewers handed me a glass of water, one was from the technical side of Tencent, and later the interviewer was also the group leader I respected the most, and the other was from qvod hr. Other interviewers ignored me as I arrived in the Hot Shenzhen sun, sweaty and almost dehydrated after every interview. Interview of examining an applicant under normal circumstances the ability to work rather than extreme environment stress ability, the interviewer is not to pour the interviewee ask, give me some tricky question bothered him but should help ease the tension and pressure should be the applicant, and the appropriate hint, let a maximum full play, this is a qualified interviewer the most basic quality.

Now let’s move on to the topic of this article. This interview question is I think a good basic knowledge of iOS development, hope you read this on the basis of understanding rather than rote memorization. Rote learning will soon be forgotten.

1 iOS Basics 1.1 How does a subclass Implement Deep Copy when its Parent Class Implements Deep Copy? How to implement deep copy if the parent class does not implement deep copy? The difference between a deep copy and a shallow copy is that a shallow copy is a pointer copy. A shallow copy of an object is equivalent to copying the pointer to the object and creating a new pointer to the object. In this case, there are two Pointers to the same object and both Pointers should be null after the object is destroyed. A deep copy is a copy of an object, which is equivalent to copying an object, creating a new object, so there are two Pointers to each object. When an object is changed or destroyed, the new object is not affected.

To implement deep copy, NSCoying protocol is required to implement – (id)copyWithZone:(NSZone *)zone method. When a property property contains the copy modifier, this method is actually called when the assignment is performed.

Once the parent implements deep copy, the subclass simply overrides copyWithZone, calls the parent’s copyWithZone method inside the method, and then implements its own property processing

The parent class does not implement deep copy, so subclasses need to process their own attributes as well as the attributes of their parent class.

KVO is the Observer mode implemented in Cocoa framework. It is usually used in conjunction with KVC to monitor changes in a value, such as the height of a View. It’s a one-to-many relationship, where a change in a value notifies all observers. NSNotification is a notification and also a one-to-many usage scenario. In some cases, KVO and NSNotification are the same, both notifying each other of state changes. The feature of NSNotification is that the observer needs to send the notification actively first, and then the observer registers the monitoring to respond, which is one step more than KVO to send the notification. However, its advantage is that the monitoring is not limited to the change of attributes, but can also monitor a variety of state changes, with a wide monitoring range and more flexible use.

A delegate is something I don’t want to do and delegate it to someone else. For example, when a dog needs to eat, it notifies its owner through a delegate, and the owner cooks, serves, and pours water for him. The dog doesn’t need to care about these operations. All it needs to do is call its delegate, and other classes do the required operations. So the delegate is one-to-one.

Blocks are another form of delegate, a form of functional programming. Using scenarios like a delegate is more flexible than a delegate, and the implementation of the proxy is more intuitive.

The general usage scenario of KVO is data, and the demand is data change, such as stock price change, we usually use KVO (Observer mode). A typical delegate usage scenario is an action, and a requirement is someone else doing something for me, like buying or selling a stock, and we use a delegate. Notification is generally used to make global notifications, such as telling people to buy good news. A delegate is a strong association, where the delegate and the agent know each other, so if you entrust someone else to buy the stock you need to know the broker, and the broker doesn’t need to know their customers. Notification is weak correlation. When good news is sent, you can respond to it without knowing who sent it, and the person who receives the message with you also can send the message without knowing who received the message.

1.3 KVC if implemented, how to carry out key value search. How to implement KVO take a look at these two blog posts KVC KVO

The GCD method allows methods in a block to be executed in the main thread by sending a block to the main thread queue. Dispatch_async (dispatch_get_main_queue(), ^{// method to execute}); NSOperation method NSOperationQueue mainQueue = [NSOperationQueue mainQueue]; NSBlockOperation operation = [NSBlockOperation blockOperationWithBlock:^{// Method to execute}]; [mainQueue addOperation:operation]; NSThread method [self performSelector:@selector(method) onThread:[NSThread mainThread] withObject:nil waitUntilDone:YES modes:nil];

[self performSelectorOnMainThread:@selector(method) withObject:nil waitUntilDone:YES];

[[NSThread mainThread] performSelector:@selector(method) withObject:nil]; RunLoop [[NSRunLoop mainRunLoop] performSelector:@selector(method) withObject:nil]; 1.5 How to Let a Timer Call a class method A timer can only call instance methods, but it can call static methods within that instance method. The timer must be added to the RunLoop and the Model must be selected to run. ScheduledTimerWithTimeInterval method to create a timer and join the RunLoop so can be used directly. If repeats select YES for the timer, be sure to call invalid for the timer at the appropriate time. Cannot be called in Dealloc because once repeats is set to yes, the timer will hold self strongly, causing Dealloc to never be called and the class can never be released. For example, it can be called in viewDidDisappear so that when the class needs to be recycled it can go into dealloc. [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerMethod) userInfo:nil repeats:YES];

-(void)timerMethod {// Call the class method [[self class] staticMethod]; }

-(void)invalid { [timer invalid]; timer = nil; } 1.6 How to override a class method: 1, implement a static method in a subclass with the same name as the base class. 2, do not use the class name when calling, but use [self class]. Calling with the class name is early bound, binding at compile time, and using [self class] is late bound, deciding which method to call at run time. 1.7 Which thread will run on when NSTimer is created. With scheduledTimerWithTimeInterval created, in which thread creation will be added to the RunLoop which thread is run in which thread created by the Timer, join the RunLoop which thread running on which thread. Id is a typedef struct objc_object * ID. Id can be understood as a pointer to an object. All oc object ids can be pointed to, the compiler does no type checking, and the id calls any existing methods without an error at compile time. Of course, if the object pointed to by this ID does not have the method, the crash will still crash.

NSObject * has to point to a subclass of NSObject, and it can only call a method that’s in NSObjec or you have to cast it.

Not all OC objects are subclasses of NSObject, and some inherit from NSProxy. The types that NSObject * can point to are subsets of IDS.

If there is any mistake in my understanding, please be sure to point out. Thank you very much! IOS core framework CoreAnimation CoreGraphics CoreLocation AVFoundation Foundation iOS core mechanism UITableView reuse ObjC memory management; Automatic release pool, How to implement runloop Runtime Block? How to implement Responder Chain NSOperation GCD data structure

Six principles of design patterns

Design the functionality of a class, how granularity (single responsibility)

Interface isolation.

If there is a bird that has the motion of flying, is it proper for an ostrich to inherit it (Richter’s substitution)

How dependencies between classes depend on the least degree of dependency coincidence (dependency inversion) The higher layer depends on the lower layer, and the lower layer cannot depend on the higher layer. Rely on interfaces, not concrete classes.

If A wants to call C, but C is A member class of B, how should it be designed? (W. Demeter)

How to design a class, how to add code without modifying it, and what lessons (open and closed) are addressed by design patterns.

Computer Technology Computer Network: TCP/IP, HTTPCDN, SPDY Computer security: RSA, AES, DES operating system: Thread, process, stack, deadlock, scheduling algorithm iOS new features, new technology iOS7 UIDynamic, SpritKit, new layout, flat iOS8 app extension, HealthKit, SceneKit, CoreLocation, TouchID, PhotoKit IOS9 third-party libraries for Apple Watch include SDWebImage, AFNetwork, JSONKit, and wax swift