IOS development will these, go to the interview, can increase the salary by 8K (recommended Collection)

Time:2021-12-25

introduce

Recently, I have been summarizing and learning. For some time, I have gained a lot from the following contents. It is also recorded here to provide you with likes and forwarding.

Statement: I hope youinterviewerDon’t use these questions as interview material to embarrass job seekers

1. The content is biased towards the bottom and fits the current IOS interview market! The content is deep and shallow, and you can continue to dig pits ()

2. I hope you can correct your learning attitude and find out and fill the gaps in time

3. Adjust the speed and depth of lectures in the next stage according to your study at this stage

catalogue
1. What is the design pattern? What design patterns do you know and briefly describe?
2. What is the difference between MVC and MVVM?
3. What is the difference between #import and #include, @ class, #import < > and #import “”?
4. What’s the difference between frame and bounds?
5. Can Objective-C classes inherit multiple classes? If not, what should be used instead? Can multiple interfaces be implemented? What is category? Is it better to override a class by inheritance or classification? Why?
6. What is the essence of @ property? How are Ivar, getter and setter generated and added to this class?
7. What are the attribute keywords and functions in @ property?
8. Difference between delegate and notification
9. What is the difference between using the weak keyword and assigning?
10、self. What’s the difference with self – >?
11. Nsstring / nsarray / nsdictionary declared with @ property often uses the copy keyword. Why? What problems may be caused if you use the strong keyword instead?
12. What is the difference between light copy and deep copy?
13. What’s wrong with this writing: @ property (nonatomic, copy) nsmutablearray * arr;?
14. What does the ISA pointer of an objc object point to? What does it do?
15. Objective-C how to memory management, talk about your views and solutions?
16. Full lifecycle of IOS uiviewcontroller?
17. How does the following code work?
18. Does Object-C have private methods? What about private variables?
19. What does the keyword const mean?
20. Write a thread safe singleton mode with pseudo code
21. Difference between category and extension
22. Tableview reuse mechanism?
23. Precautions for IOS memory use and optimization?
24. IOS how do you optimize memory in your project?
25. Write a complete proxy, including declaration and implementation
26. Have you ever used GCD in IOS projects? for instance
27. Differences between GCD and nsoperation
28. Write the method code of returning from the child thread to the main thread in GCD mode
29. What is the method of creating threads in OC? If the code is executed in the main thread, what is the method?
30. How do you encapsulate a view (stem and story)

Electronic interview document: I made a PDF document. Because developer can’t upload files, it’s convenient for everyone to read, watch and learn

Materials presented by friends:

For those who need interview, resume, internal promotion and advanced learning recently, you can see ↓↓↓↓↓↓

Introduction to IOS to advanced data sorting:https://docs.qq.com/doc/DVU5LY1Bsb3dSZ3Nn

1. What is the design pattern? What design patterns do you know and briefly describe?

Design patternIt is a summary of code design experience that is repeatedly used, known by most people, classified and catalogued.

Singleton mode:The singleton pattern ensures that there is only one instance of a class and provides a full play access point to access it.Click to view the specific details
Factory mode:The factory parent class is responsible for defining the public interface for creating product objects, while the factory subclass is responsible for producing specific product objects, that is, creating different product objects through constant factory subclasses.Click to view the specific details
Proxy mode:Provide a proxy for an object, and the proxy object controls access to the original object.Click to view the specific details
Adapter mode:Convert an interface into another interface that the customer wants, so that those classes that could not work together due to interface incompatibility can work together. The alias of adapter pattern is wrapper pattern, which is a structural design pattern.Click to view the specific details
Decorator mode:Dynamically add some additional functions to an object without changing the original object.Click to view the specific details


2. What is the difference between MVC and MVVM?

MVC
MVC (model view controller) mode structure diagram can be divided into three parts: model, view and controller. Its roles in MVC mode are:
Model: the model manages the data of the application, responds to requests for its status information (usually from view), and responds to instructions to change the status (usually from controller).
View: display of view management data.
Controller: the controller interprets the user’s input and notifies the model and view to update the status
All communications are unidirectional.
Advantages: the controller is downsized and the details inside the view are encapsulated. The outside world does not know the specific implementation inside the view
Disadvantages: view and controller depend on model

MVVM
MVVM (model view model) is to solve the problem of overstaffing. The idea of MVVM is to separate the UI control logic from the business logic in the controller, and extract a view model to complete the UI control logic. The controller only needs to be responsible for the business logic

The only difference is that the view model can call the method defined by the model, obtain data from the model for the view, and preprocess the data so that the view can be used directly. View can also issue user operation commands to view model to change the model. MVVM implements a two-way binding mechanism.

Advantages: it reduces the coupling between view and model; Business logic and view logic are separated.
Disadvantages: the two-way binding of view and model makes it difficult to locate the bug. If either of them has a problem, the other will also have a problem; Added glue code.

3. What is the difference between #import and #include, @ class, #import < > and #import “”?

1>. #importIs the keyword of the Objective-C import header file,#includeIs the keyword of C / C + + import header file. Use#importThe header file will be automatically imported only once and will not be imported repeatedly.
2>.@classTell the compiler to view the class implementation file only when the declaration of a class is executed, which can solve the mutual inclusion of header files.
3>. #Import < > is used to contain the header file of the system#import””Used to contain user header files.


4. What’s the difference between frame and bounds?

frame:The position and size of the view in the parent view coordinate system. (the reference point is the coordinate system of the parent view)

bounds:The position and size of the view in its own coordinate system. (the reference point is its own coordinate system)


5. Can Objective-C classes inherit multiple classes? If not, what should be used instead? Can multiple interfaces be implemented? What is category? Is it better to override a class by inheritance or classification? Why?

OC cannot inherit more than one. OC is single inheritance. Classification and protocols can sometimes be used instead of multiple inheritance
Multiple interfaces (protocols) can be implemented
Category is the category; In general, the method of good classification and rewriting classes with category is only effective for this category and will not affect the relationship between other classes and original classes.


6. What is the essence of @ property? How are Ivar, getter and setter generated and added to this class?

@The essence of property is: @ property = Ivar + getter + setter

There are two concepts of “property”: Ivar (instance variable) and getter + setter (access method)
As a feature of Objective-C, the main function of “property” is to encapsulate the data in the object. Objective-C objects usually save the data they need as various instance variables. Instance variables are generally accessed through the access method. Where the getter is used to read the variable value and the setter is used to write the variable value.


7. What are the attribute keywords and functions in @ property?

nonatomic :Non atomic operation. Determines whether the setter and getter methods generated by the compiler are atomic operations. Generally, nonatomic is used with high efficiency.
atomic:Multithreading is safe, but the performance is low
strong:Holding characteristics. The setter method preserves the passed in parameter first and then assigns a value. The retaincount of the passed in parameter will be + 1.
copy :Copy properties. The setter method copies a copy of the incoming object, and a new variable is required.
assign:For basic data types
readwrite:Readable and writable features. Getter and setter methods need to be generated
readonly:Read only property. Only getter methods will be generated, and setter methods will not be generated. You do not want the property to change outside the class.
retainStrong: equivalent to in arc


8. Difference between delegate and notification

Both are used to deliver messages. The main difference is that one is one-to-one and the other is one to many
notification:There is no connection between the two to realize one to many message forwarding
delegate:You need to establish a connection between the two, or you can’t call the proxy’s method


9. What is the difference between using the weak keyword and assigning?

1>. In arc, when circular references may occur, it is often necessary to use break at one end, such as delegate proxy attribute.
2>. It has already made a strong reference to it. It is unnecessary to make a strong reference again. At this time, break will also be used. The custom iboutlet control property generally also uses break (because the subviews array of the parent control already has a strong reference to it).

difference:
Assign can use non OC objects, while break must be used for OC objects.
Weak indicates that the attribute defines a “non ownership relationship”. When the object referred to by the attribute is destroyed, the attribute value will be automatically cleared (NIL).


10、self. What’s the difference with self – >?

1>. self. Call the get method or set method
2>. Self is the current itself and a pointer to the current object
3>. Self – > is a direct access member variable


11. Nsstring / nsarray / nsdictionary declared with @ property often uses the copy keyword. Why? What problems may be caused if you use the strong keyword instead?

Use @ property to declare nsstring, nsarray and nsdictionary. The copy keyword is often used because they have corresponding variable types: nsmutablestring, nsmutablearray and nsmutabledictionary, There may be assignment operations between them (that is, assigning the variable to the immutable). In order to ensure that the string value in the object will not change inadvertently, a copy should be made when setting the new attribute value.

1>. Because the parent class pointer can point to the child class object, the purpose of using copy is to keep the properties of this object from being affected by the outside world. No matter whether it is a variable object or a non variable object, I own an immutable copy.
2>. If we use strong, this attribute may point to a variable object. If the variable object is modified externally, this attribute will be affected.
Summary: the purpose of using copy is to prevent that when assigning a variable type object to an immutable type object, the sending change of the value of the variable type object will inadvertently tamper with the original value of the immutable type object.


12. What is the difference between light copy and deep copy?

Shallow copy:A copy of an object address. The source object and the copy object are the same object
Deep copy:A copy of an object. The source object and the copy object are two different objects


13. What’s wrong with this writing: @ property (nonatomic, copy) nsmutablearray * arr;?

Problem: when adding, deleting or modifying elements in the array, the program will crash because it can’t find the corresponding method.

-[__NSArrayI removeObjectAtIndex:]: 
unrecognized selector sent to instance 0x7fcd1bc30460

After copy, an immutable object is returned (that is, array is of nsarray type, and an object of nsarray type cannot call the method of an object of nsmutablearray type)
Reason: copy is to copy an immutable nsarray object, and the nsarray object cannot be added / modified.


14. What does the ISA pointer of an objc object point to? What does it do?

Point to his class object so that you can find the method on the object


15. Objective-C how to memory management, talk about your views and solutions?

Objective-C has three main memory management methods: arc (automatic memory counting), manual memory counting and memory pool.
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 applies and who releases; The principle of who adds and who releases.
3>. Memory release pool: put the memory to be released into one pool. When the pool is drained, all memory space in the pool will be released automatically. The release operation of memory pool is divided into automatic and manual. Automatic release is affected by the runloop mechanism.


16. Full lifecycle of IOS uiviewcontroller?

In order of execution:

1>. initWithCoder:Triggered when initialized through NIB file.
2>. awakeFromNib:An error occurs when the nib file is loadedawakeFromNibTo each object in the nib file.
3>. loadView:Start loading the view that comes with the view controller.
4>. viewDidLoad:The view of the view controller is loaded.
5>. viewWillAppear:The view of the view controller will be displayed on the window.
6>. updateViewConstraints:The view of the view controller starts updating the AutoLayout constraint.
7>. viewWillLayoutSubviews:The view of the view controller will update the location of the content view.
8>. viewDidLayoutSubviews:The view of the view controller has updated the location of the view.
9>. viewDidAppear:The view of the view controller has been displayed on the window.
10>. viewWillDisappear:The view of the view controller will disappear from the window.
11>.viewDidDisappear:The view of the view controller has disappeared from the window.


17. How does the following code work?
- (void)viewDidLoad {

[super viewDidLoad];

NSLog(@"1");

dispatch_sync(dispatch_get_main_queue(), ^{

NSLog(@"2");
});

NSLog(@"3");
}

Output only: 1. (the main thread is deadlocked because the viewdidload method opens a main thread by default and then executesdispatch_sync(dispatch_get_main_queue(), ^{...});It will cause you to wait for me and I will wait for you, resulting in deadlock.


18. Does Object-C have private methods? What about private variables?

1>. OC has no modifier like @ private to modify the method, just write it in H file is the public method
2>. If you’re not here H file, only in M file, or in If it is declared in the class extension of m file, it is basically similar to private methods. You can use class extension to add private methods and private variables
3>. Global variables decorated with private are private variables


19. What does the keyword const mean?

const int a;
int const a;
const int *a;
int const *a;
int * const a;
int const * const a;

1>. The first two functions are the same: A is a constant integer
2>. The third and fourth means that a is a pointer to a constant integer (an integer is not modifiable, but the pointer can)
3>. A is a constant pointer to an integer (the integer pointed to by the pointer can be modified, but the pointer cannot be modified)
4>. The last one means: A is a constant pointer to a constant integer (the integer pointed to by the pointer is not modifiable, and the pointer is not modifiable)


20. Write a thread safe singleton mode with pseudo code


static XXManager * instance = nil;
+ (instancetype)shareInstance {
      static dispatch_once_t onceToken;
      dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
});
return instance;
}

+ (id)allocWithZone:(struct _NSZone *)zone {

      static dispatch_once_t onceToken;
      dispatch_once(&onceToken, ^{
        instance = [super allocWithZone:zone];
});
return instance;
}
- (id)copyWithZone:(NSZone *)zone {
return instance;
}

21. Difference between category and extension

1>. A category has a name, but a class extension does not have a category name. It is a special category.
2>. Classes can only extend methods (properties are just declarations, not really implemented), and class extensions can extend properties, member variables and methods.
3>. Inheritance can add, modify or delete methods, and add properties.


22. Tableview reuse mechanism?

Uitableview saves memory by reusing cells: it specifies a reuse identifier for each cell, that is, it specifies the type of cell. When the cell on the screen slides out of the screen, the system will add the cell to the reuse queue and wait for reuse. When a new cell slides into the screen from outside the screen, Look in the reuse queue to see if there are any cells that can be reused. If so, take them for use. If not, create one for use


23. Precautions for IOS memory use and optimization?

Reuse issues:asUITableViewCellsUICollectionViewCellsUITableViewHeaderFooterViews。 Set the correctreuseIdentifier, fully reuse
1> Don’t use too complexXIB/StoryboardWhen loaded, theXIB/storyboardAll required resources, including pictures, are loaded into memory.
Try to make the views opaque:When option is no, the translucency of the layer depends on the image and the layer synthesized by itself, which can improve the performance
Select the correct data structure:Learning to select the most appropriate array structure for the business scenario is the basis for writing efficient code.
Gzip / zip compression:When downloading relevant attachments from the server, you can compress them through gzip / zip and then download them, so that the memory is smaller and the download speed is faster.
Delayed loading:For data that should not be used, use deferred loading. For views that do not need to be displayed immediately, use deferred loading. For example, the prompt interface displayed when the network request fails may never be used, so delayed loading should be used.
Data cache:The row height of the cell should be cached, so that when reloading data, the efficiency is also very high.
For those network data that do not need to be requested every time, they should be cached. It can be written to the database or stored through plist file
Processing memory warning:Generally, memory warnings are handled uniformly in the base class to release relevant unused resources immediately


24. IOS how do you optimize memory in your project?

This question is sometimes in the written examination, and sometimes some interviewers will ask you this question in the interview

1>. Avoid large Xib (Xib consumes more CPU resources than frame)
2>. Don’t block the main thread, try to put time-consuming operations into sub threads
3>. Reuse and deferred loading
4>. Minimize the number and hierarchy of views
5>. To optimize tableview, the following measures can be taken to improve the scrolling performance of tableview:

  • Reusing cells using ruseidentifier correctly
  • 采用懒加载即延迟加载的方式加载cell上的控件
  • 当TableView滑动的时候不加载
  • 缓存cell的高度。在呈现cell前,把cell的高度计算好缓存起来,避免每次加载cell的时候都要计算
  • 尽量使用不透明的UI控件

25、写一个完整的代理,包括声明、实现


// 创建
@protocol PersonDelagate
@required
-(void)eat:(NSString *)foodName;
@optional
-(void)run;
@end

// 声明 .h
@interface Person: NSObject<PersonDelagate>
@end

// 实现 .m
@implementation Person

- (void)eat:(NSString *)foodName {
NSLog(@"吃:%@", foodName);
}

- (void)run {
   NSLog(@"run");
}
@end


26、iOS 你在项目中用过 GCD 吗?举个例子

用过。比如 网络请求数据成功之后刷新列表

   [HTTPRequest POST:kbazaarUrl parameter:nil success:^(id resposeObject) { 
       /**网络请求成功之后处理数据*/
        if (Success) {
              //处理数据 ... 
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableView reloadData];  
            });
        }else{
            [weakSelf failEndRefreshStatus:0];
            [MBProgressHUD LY_ShowError:resposeObject[@"msg"] time:2.0];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD LY_ShowError:kNoNetworkTips time:2.0];
    }];


27、GCD 与 NSOperation 的区别

NSOperation:相对于GCD来说,更加强大。可以给operation之间添加依赖关系、取消一个正在执行的operation、暂停和恢复operationQueue等

GCD: 是一种更轻量级的,以FIFO(先进先出,后进后出)的顺序执行并发任务。使用GCD我们并不用关心任务的调度情况,而是系统会自动帮我们处理。但是GCD的短板也是非常明显的,比如我们想要给任务之间添加依赖关系、取消或者暂停一个正在执行的任务时就会变得束手无策。


28、写出使用GCD方式从子线程回到主线程的方法代码

dispatch_sync(dispatch_get_main_queue(), ^{ });

29、OC中创建线程的方法是什么?如果在主线程中执行代码,方法是什么?

// 创建线程的方法

- [NSThread detachNewThreadSelector:nil toTarget:nil withObject:nil]

- [self performSelectorInBackground:nil withObject:nil];

- [[NSThread alloc] initWithTarget:nil selector:nil object:nil];

- dispatch_async(dispatch_get_global_queue(0, 0), ^{});

- [[NSOperationQueue new] addOperation:nil];

// 主线程中执行代码的方法

- [self performSelectorOnMainThread:nil withObject:nil waitUntilDone:YES];

- dispatch_async(dispatch_get_main_queue(), ^{});

- [[NSOperationQueue mainQueue] addOperation:nil];

30、你是怎么封装一个view的

笔者就曾遇到过这个问题。当时这样,原题目是:怎么用纯代码或者xib实现一个View的组件化。看到这个题目的时候我就懵逼了,就好像考试的过程中碰到不会的题目一样,这里直接是0分。后来面试的过程中,我就用面试官此题怎解。霹雳哗啦给我说了一大堆,最后我问是不是封装一个View?他回答说:是的! 封装任意一个View.之后就问我实现思路要实现什么方法。然后我就说实现initWIthFrame:然后创建需要的控件,最后直接通过添加个类方法show出来即可。因为我也不知道这个任意的View到底是个什么View,就将TA假象成一个弹框好了。结果面试官继续追问过好几次还要实现什么方法呢??? 我沉思了好久好一会(明明就差不多是这样子左右,为啥他还继续追问呢)。。。面试官可能感受到了空中传来一阵尴尬气氛之后,说不知道没关系。。。之后又问了一个类似QQ消息点击tabBar上面的item然后列表的小红点有类似西红柿爆炸的效果。经过上一个骚问题,我已经知道面试已经凉凉了(而且听说接手的项目是之前废弃半年的棋牌项目,现在重新启动) 我直接说不知道。对于此面试官来说,我可能是个菜鸡吧。我觉得身心受到了严重的打击。可能还是不够努力吧!

1>. 可以通过纯代码或者xib的方式来封装子控件
2>. 建立一个跟view相关的模型,然后将模型数据传给view,通过模型上的数据给view的子控件赋值

- (instancetype)initWithFrame:(CGRect)frame {

  if(self = [super initWithFrame:frame]) {

          [self setupUI];
 }
return self;

}
/*** 通过xib初始化控件时一定会走这个方法*/

- (id)initWithCoder:(NSCoder *)aDecoder {

    if(self = [super initWithCoder:aDecoder]) {
        [self setupUI];
}

return self;

}

- (void)setupUI {
// 初始化代码
}

朋友赠送的资料:

最近需要面试,简历,内推,学习进阶的可以看看

iOS入门到进阶资料整理:https://docs.qq.com/doc/DVU5LY1Bsb3dSZ3Nn