- Hands-On Design Patterns with Swift
- Florent Vilmart Giordano Scalzo Sergio De Simone
- 137字
- 2021-07-02 14:45:14
Using nullable, nonnull, _Nullable, and _Nonnull
With NS_ASSUME_NON_NULL_BEGIN/_END, you may need to mark particular properties as nullable as all of the code enclosed will be translated without optionals.
These four keywords are used to mark individual arguments or properties—their usage is straightforward:
- nullable
- nonnull
- _Nullable
- _Nonnull
Using a nullable property will produce Optional, which you'll safely need to unpack in Swift. Using nonnull will produce non-optional properties or variables. nullable and nonnull keywords are exclusively used in the context of declaring @property on Objective-C interfaces.
_Nullable and _Nonnull keywords are used in all other cases:
- Declaring local variables
- Arguments to methods
- Return types of methods
- Declaring ivars
You can use the following table as a reference if you ever need to quickly look up the different possibilities and how they translate in both languages:

推薦閱讀
- 計(jì)算機(jī)綜合設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)
- Game Development with Swift
- 企業(yè)大數(shù)據(jù)系統(tǒng)構(gòu)建實(shí)戰(zhàn):技術(shù)、架構(gòu)、實(shí)施與應(yīng)用
- Oracle RAC 11g實(shí)戰(zhàn)指南
- SQL查詢:從入門到實(shí)踐(第4版)
- Live Longer with AI
- INSTANT Cytoscape Complex Network Analysis How-to
- 深入淺出 Hyperscan:高性能正則表達(dá)式算法原理與設(shè)計(jì)
- 數(shù)據(jù)科學(xué)工程實(shí)踐:用戶行為分析與建模、A/B實(shí)驗(yàn)、SQLFlow
- 探索新型智庫發(fā)展之路:藍(lán)迪國際智庫報(bào)告·2015(下冊)
- 數(shù)據(jù)科學(xué)實(shí)戰(zhàn)指南
- 貫通SQL Server 2008數(shù)據(jù)庫系統(tǒng)開發(fā)
- Unity 2018 By Example(Second Edition)
- 云計(jì)算寶典:技術(shù)與實(shí)踐
- 數(shù)據(jù)庫應(yīng)用系統(tǒng)技術(shù)