We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SomeClass!
nil
nullable
SomeClass?
nonnull
SomeClass
null_unspecified
NSNotificationName
Notification.Name
Swift 诞生即看重安全,而硬编码是代码中很难去保证安全性的一环。Swift 4.2 中的 Notification.Name 即通知名更改为更加安全的做法,而为了和 Obj-C 中的 NSNotificationName 可以兼容,需要在 Obj-C 中的声明后增加 NS_EXTENSIBLE_STRING_ENUM 宏。
NS_EXTENSIBLE_STRING_ENUM
NSNotificationNameDidUpdate
.didUpdate
Notification
DidUpdateNotification
.DidUpdate
NSNotificationNameDidUpdateNotification
.NSNotificationNameDidUpdate
DidUpdate
The text was updated successfully, but these errors were encountered:
kingcos
No branches or pull requests
Preface
Optional 与 Nullability
SomeClass!
),而在 Swift 中这代表开发者要保证值不为nil
,编译器将不再提示。当属性是 Block 时,若直接调用了为nil
的 Closure 时,将会出现崩溃。nullable
SomeClass?
nonnull
SomeClass
null_unspecified
SomeClass!
NSNotificationName
与Notification.Name
Swift 诞生即看重安全,而硬编码是代码中很难去保证安全性的一环。Swift 4.2 中的
Notification.Name
即通知名更改为更加安全的做法,而为了和 Obj-C 中的NSNotificationName
可以兼容,需要在 Obj-C 中的声明后增加NS_EXTENSIBLE_STRING_ENUM
宏。NS_EXTENSIBLE_STRING_ENUM
宏后,Swift 中可以使用类似枚举的语法;NSNotificationNameDidUpdate
->.didUpdate
NSNotificationName
,Obj-C 变量结尾含有Notification
,也会进行忽略,经过测试此条并不适用其他声明NS_EXTENSIBLE_STRING_ENUM
的自定义类型,eg.DidUpdateNotification
->.DidUpdate
;NSNotificationNameDidUpdateNotification
->.NSNotificationNameDidUpdate
;DidUpdateNotification
&DidUpdate
在 Swift 中均为.DidUpdate
=> Ambiguous use of 'DidUpdate'。The text was updated successfully, but these errors were encountered: