iOS精品文章-架构&模式

【iOS】设计模式

2017-08-10  本文已影响18人  清無

1。建造型模式Creational

2。结构型模式Structural

MVC

Extensions and Delegation.

Facade

3。行为型模式Behavioral

The memento pattern captures and externalizes an object's internal state.

Storyboard设置VC的Restoration ID
func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
  return true
}

func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
  return true
}
override func encodeRestorableState(with coder: NSCoder) {
  coder.encode(currentAlbumIndex, forKey: Constants.IndexRestorationKey)
  super.encodeRestorableState(with: coder)
}

override func decodeRestorableState(with coder: NSCoder) {
  super.decodeRestorableState(with: coder)
  currentAlbumIndex = coder.decodeInteger(forKey: Constants.IndexRestorationKey)
  showDataForAlbum(at: currentAlbumIndex)
  horizontalScrollerView.reload()
}

链接

https://www.raywenderlich.com/160651/design-patterns-ios-using-swift-part-12
https://github.com/ochococo/Design-Patterns-In-Swift

上一篇下一篇

猜你喜欢

热点阅读