当前位置:网站首页>Swift foundation features unique to swift
Swift foundation features unique to swift
2022-06-24 08:13:00 【Fenghanxu】
I always feel that what I write is not technology , But feelings , One tutorial after another is the trace of one's own journey . Success with expertise is the most replicable , I hope my path will make you less detours , I hope I can help you erase the dust of knowledge , I hope I can help you clarify the context of knowledge , I hope there will be you and me on the top of technology in the future .
Preface
This article introduces swift relative oc,swift Unique usage , In combination with the requirements in development
On the subject
internal
internal Decorated attributes , There is always only one object address , It's like a single case
class Service {
internal static let name = "fenghanxu"
}
controller A Use attributes 
controller B Use attributes 
Print the results
A controller , The attribute address is : 0xb21b7768d2b563c4
B controller , The attribute address is : 0xb21b7768d2b563c4
A controller , The attribute address is : 0xb21b7768d2b563c4
throws
When we use the system method, we often see that the system has a writing method throws Property to modify the method . for example : Look at the picture below .
If the method is useful throws Embellished words , You need to throw an exception when using the method .
There are two common ways to use this method :

Usage mode 1:
Usage mode 2:
guard
stay swift In development guard It's very common , General usage , for example :A Property does not confirm whether there is a value , But we need to use A Value , If A You can't go on without them . So you need to use guard Yes A Unpack to see if there is value , For example, look at the following code .

because num_0 Do not confirm whether there is a value =, So you need to unpack before using 
The second is to use guard The most common use is in closures .
Explain why to self Unpacking , Because after the closure comes back, the current self I don't know if it still exists , If you are released, you will not be able to self The properties in the , So it's using self Before the properties of self Unpacking , If there is self Just go down . Quit without .
If it is not unpacked for use self Will bring question mark (?) for example : Look at the code below 
(?) Use of question marks
What situation attribute is followed by a question mark . This is a little bit easier 
For example, the picture above , If tableview When it is created, it is created like the following image form , When you use it, you will tableview Followed by a question mark . Because when using this object , I don't know if it has become a powerful object , If not, do not set related properties , Only if the strength is changed .
So what is the general requirement to use the above image to create attributes .
In a controller , You need to pop up a box , This box is only created when it needs to be used , If you create attributes in the form of the above picture , The box will be removed when you run out of it .
(??) Use of double question marks

As can be seen from the picture above , We are going to put height Assign a value to an object statusBarHeight, however height It's from statusBarManager Objects are taken out , however statusBarManager I don't know if it exists , If it doesn't exist ,height There is no such thing as , however statusBarHeight Confirm that you need to get a value . So when you use a value, you need to bring a Double question mark , If height If you don't get the value, you will get the default value after the double question mark .
边栏推荐
- Chapitre 2: dessiner une fenêtre
- Opening chapter of online document technology - rich text editor
- Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
- Simple summary of lighting usage
- 解决笔记本键盘禁用失败问题
- decltype用法介绍
- On the H5 page, the Apple phone blocks the content when using fixed to locate the bottom of the tabbar
- Mousse shares listed on Shenzhen Stock Exchange: gross profit margin continued to decline, and marketing failed in the first quarter of 2022
- [run the script framework in Django and store the data in the database]
- GraphMAE----論文快速閱讀
猜你喜欢

Moonwell Artemis is now online moonbeam network

快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning

【资料上新】迅为基于3568开发板的NPU开发资料全面升级

Pagoda panel installation php7.2 installation phalcon3.3.2

软件工程导论——第二章——可行性研究

Backup and restore SQL Server Databases locally

Signature analysis of app x-zse-96 in a Q & a community

蓝桥杯_N 皇后问题

疫情下更合适的开发模式

首次曝光 唯一全域最高等级背后的阿里云云原生安全全景图
随机推荐
VsCode主题推荐
Jenkins is too old try it? Cloud native ci/cd Tekton
4-operation list (loop structure)
某问答社区App x-zse-96签名分析
对于flex:1的详细解释,flex:1
In the post epidemic era, the home service robot industry has just set sail
快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning
Swift Extension NetworkUtil(网络监听)(源码)
Oracle advanced SQL qualified query
Utilisation de la fermeture / bloc de base SWIFT (source)
L1-019 who goes first (15 points)
一文理解同步FIFO
Search and recommend those things
Auto usage example
Interview tutorial - multi thread knowledge sorting
Saccadenet: use corner features to fine tune the two stage prediction frame | CVPR 2020
Pagoda panel installation php7.2 installation phalcon3.3.2
ImportError: cannot import name ‘process_ pdf‘ from ‘pdfminer. Pdfinterp 'error completely resolved
MySQL source and target table row count check
搜索与推荐那些事儿