owned this note changed 6 years ago
Published Linked with GitHub

關於Smart KeyPath - Chiao-Te, Ni

所有議程請見議程表

歡迎來到 https://hackmd.io/@iPlayground/2019 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。

請從這裡開始

Slide

  • 範例: let keyPath = \UIView.frame
  • 延後取值的特性
  • 也可以用在非NSObject
  • KeyPath -> read only
  • WritableKeyPath -> read/write (for variable)
  • ReferenceWritableKeyPath -> read/write (for variable/constant, Class only)
    * 系統會根據屬性(如frame 或是 width) 自動回傳不同的keyPath型別
    • e.g. \UIView.frame.size -> ReferenceWritableKeyPath
    • e.g. \UIView.frame.width -> KeyPath
​​​​* 實際應用範例:對array做extension  驗證物件得值是否符合預期
ticket.sorted(\.price, by: <)

second case

hold check array

Fluent autoLayout

coding syle: Fluent interface

before

label.translatesAutoresizingMaskIntoConstraints = false
label.constraint(...).isactive = true

after

label
.setAnchor(\.widthanchor, ..., to: view.widthanchor)
.setAnchor(\.heightanchor, ..., to: view.heightanchor)

Fluent Builder
@dynamicMemberLookup

//java
Type variableName = new Type.builder()
    .a() -> return builder
    .b() -> return builder
    .build() -> 這邊才把實體new出來

conclusion

tags:iPlayground2019
Select a repo