当前位置:网站首页>IOS interview preparation - Objective-C
IOS interview preparation - Objective-C
2022-07-29 04:42:00 【smallcatlei】
iOS Interview preparation - ios piece
ios Interview preparation - objective-c piece
ios Interview preparation - Online
IOS Interview preparation - C++ piece
iOS Interview preparation - Other articles
Swift And oc difference
Swift and Objective-C Share a set of runtime environment ,Swift The type can be bridged to Objective-C( I'll call it OC), vice versa .
Swift advantage
Swift Easy to read , Simplification of grammar and file structure .
Swift Easier to maintain , The structure of the document is clearer after separation .
Swift More secure , It's a type safe language .
Swift Less code , Simple grammar , Can save a lot of redundant code
Swift Faster , Higher performance .
Swift shortcoming
No one used oc many ( It's not obvious now )
Because the cost of language conversion Many companies continue to use oc
KVC
KVC By NSKeyValueCoding A mechanism for enabling informal agreements , Object uses this protocol to provide indirect access to its properties .
ios13 prohibit kvc Access private properties .
kvc Set the value
Setting a value is to call a function :setValue:forKey, The internal process is as follows :
First, the corresponding setter Method ,setkey、_setKey、setIsKey, without ,
Check accessInstanceVariablesDirectly Method returns YES, If NO Go directly to setValue:forUndefinedKey: Method . If YES,
Search member variables in turn _key,_isKey,key,isKey . If found, assign him a value , Otherwise, call setValue:forUndefinedKey:
setValue:forUndefinedKey: Exception thrown by default
If not crash You can get one NSObject The classification of , rewrite setValue:forUndefinedKey: Make an empty implementation .
kvc Value
Value is called valueForKey: , The internal process is as follows :
● First getter Method ,getKey、key、isKey、_key If it is found, it will directly call . If it is BOOL perhaps Int Equivalent type , It will be packaged as a NSNumber object .
● Check class method + (BOOL)accessInstanceVariablesDirectly, If you return YES( Default behavior ), So it's the same as the previous setting , Will press _key,_isKey,key,isKey Search the member variable name in the order of .
● If you haven't found it yet , Call the object directly valueForUndefinedKey: Method , This method throws an exception by default .
KVO
iOS In what way to implement the KVO?(KVO What is the essence of ?)
answer . When an object uses KVO monitor ,iOS The system will modify this object isa The pointer , To point to a new passage Runtime Subclass created dynamically , Subclasses have their own set Method realization ,set Method implementation will call in sequence willChangeValueForKey Method 、 The original setter Method realization 、didChangeValueForKey Method , and didChangeValueForKey The listener will be called inside the method observeValueForKeyPath:ofObject:change:context: Monitoring methods .
How to trigger manually KVO?
answer . When the value of the monitored property is modified , Will trigger automatically KVO. If you want to trigger it manually KVO, We need to call willChangeValueForKey and didChangeValueForKey Method can be triggered manually without changing the attribute value KVO, And these two methods are indispensable , The trigger code is still between them .
other
iOS: Understand OC Classes and metaclasses in :
https://www.jianshu.com/p/51b4019a8df2
il、Nil、NULL、NSNull The difference between
nil: A null pointer to an object , Yes objective c id Object null value .
Nil: Null pointer to a class , Indicates that the class is null .
NULL: Point to other types ( Such as : Basic types 、C type ) The null pointer of , Used to assign null values to non object pointers .
NSNull: In a collection object , Objects representing null values .
try in return
stay try Inside return,finally Will be in return After performing , So in this case finally There will be problems in processing the return value , So don't put return discharge try Inside .
Self increasing problem
There are two ways ,count The value of will not change . principle :count This value 0 Put it in storage , then count Self adding 1 become 1, Finally, assign the temporary value to count,count The final value is 0
int count = 0;
count = (count++);
count = count++;
The following value will be increased by one
count = ++count;
边栏推荐
- 读懂 互联网巨头 【中台之战】 以及 中台 发展思维
- Sign the college entrance examination
- [c language] PTA 7-48 find the number of combinations
- TypeError: Cannot read properties of undefined (reading ‘then‘)
- On the use of pyscript (realizing office preview)
- DASCTF2022.07赋能赛
- 使用更灵活、更方便的罗氏线圈
- Integration of Nan causes in pytorch training model
- 央企建筑企业数字化转型核心特征是什么?
- Vscode one click compilation and debugging
猜你喜欢
Post export data, return
Corresponding order of 18 and 25coco data of openpose and joint points
Reveal安装配置调试
mujoco和mujoco_py安装以及解决libXcursor.so.1:NO such dictionary
Definition and implementation of stack and queue (detailed)
Several simple and difficult OJ problems with sequential force deduction
Google browser opens the web page and out of memory appears
Visio draw grid
What is the difference between field, variable and property
GCC基础知识
随机推荐
Pytoch automatic mixing accuracy (AMP) training
Dabao and Erbao
i++与++i详解
Laya中的A星寻路
Mongo shell interactive command window
如何避免示波器电流探头损坏
(heap sort) heap sort is super detailed, I don't believe you can't (C language code implementation)
删除word文档中的空白页
JVM (heap and stack) memory allocation
Oracle update and delete data
【Express连接MySQL数据库】
GCC基础知识
The most complete NLP Chinese and English stop words list in the whole station (including punctuation marks, which can be copied directly)
[c language] PTA 7-50 output Fahrenheit Celsius temperature conversion table
命令行交互工具(最新版) inquirer 实用教程
Command line interactive tools (latest version) inquirer practical tutorial
Star a pathfinding in LAYA
[C language] PTA 7-91 output leap year
Pyqt5 learning pit encounter and pit drainage (1) unable to open designer.exe
Vscode one click compilation and debugging