官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 固安县| 无棣县| 和顺县| 双牌县| 焦作市| 南丰县| 东港市| 台中县| 湘阴县| 藁城市| 石林| 始兴县| 承德市| 深圳市| 乐东| 滨州市| 海口市| 乐亭县| 大邑县| 托克托县| 会东县| 崇文区| 珲春市| 潼关县| 南京市| 宁都县| 安宁市| 永寿县| 弥渡县| 滕州市| 盈江县| 尼木县| 桑日县| 鹤山市| 新巴尔虎左旗| 保康县| 阜阳市| 睢宁县| 合作市| 衡阳市| 于都县|