LoginSignup
0
0

More than 5 years have passed since last update.

Notification key name 寫法的改變 - Swift 3

Posted at

碰到需要用到 Notification 內建的 key name ,
發現在 Swift 3 / iOS 10 的寫法改變了

iOS 10 SDK 很大的改變之一就是很多取得的方式都物件化了,
大大降低 C style 的取用方式

今天是碰到觀察 keyboard 變化發現的,
例如:

UIKeyboardWillHideNotification

這是用來觀察鍵盤即將隱藏的 notification 的 key name ,
在 Xcode 8 裡面則會被發現被 IDE 告知:

'UIKeyboardWillHideNotification' has been renamed to 'NSNotification.Name.UIKeyboardWillHide'

這時候 IDE 會幫你改成

NSNotification.Name.UIKeyboardWillHide

這樣物件類型的寫法即可。

巢狀 struct

在追這個 NSNotification.Name 的定義的時候,
發現官方是用巢狀 struct 的方式定義這一群的 notification names 。

這個寫法應該不是新的,只是目前還沒這樣寫過。
之後可以看情境來嘗試看看來包裝這一類的環境變數方便存取。

這個用法詳細的原因就還要再去找找資料了~

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0