- 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:

推薦閱讀
- 數據要素安全流通
- Building Computer Vision Projects with OpenCV 4 and C++
- Test-Driven Development with Mockito
- Python數據分析、挖掘與可視化從入門到精通
- MySQL從入門到精通(第3版)
- Mockito Cookbook
- OracleDBA實戰攻略:運維管理、診斷優化、高可用與最佳實踐
- 跟老男孩學Linux運維:MySQL入門與提高實踐
- Proxmox VE超融合集群實踐真傳
- Oracle RAC日記
- 企業大數據處理:Spark、Druid、Flume與Kafka應用實踐
- 數據庫原理與設計實驗教程(MySQL版)
- 數據之美:一本書學會可視化設計
- Oracle 11g數據庫管理與開發基礎教程
- Artificial Intelligence for Big Data