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

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:

主站蜘蛛池模板: 周口市| 天长市| 晋宁县| 武川县| 祁阳县| 张家界市| 东乌| 德清县| 新丰县| 敦化市| 上饶县| 义马市| 盐山县| 山西省| 文昌市| 冀州市| 昌宁县| 呼和浩特市| 同心县| 郯城县| 祁连县| 新田县| 万山特区| 嵊州市| 明溪县| 民丰县| 八宿县| 江口县| 丹棱县| 青阳县| 阜平县| 曲沃县| 介休市| 长子县| 辽阳市| 措美县| 青神县| 鄂伦春自治旗| 县级市| 紫金县| 平邑县|