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

推薦閱讀
- 計算機組成原理與接口技術:基于MIPS架構實驗教程(第2版)
- MySQL數據庫進階實戰
- MySQL高可用解決方案:從主從復制到InnoDB Cluster架構
- 數據庫應用實戰
- 云數據中心基礎
- Learning Spring Boot
- 大數據:規劃、實施、運維
- 大數據營銷:如何讓營銷更具吸引力
- IPython Interactive Computing and Visualization Cookbook(Second Edition)
- Hadoop集群與安全
- 機器學習:實用案例解析
- 中國云存儲發展報告
- Spring Boot 2.0 Cookbook(Second Edition)
- Hands-On Deep Learning for Games
- 數據分析實踐:專業知識和職場技巧