You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Codable 是 Decodable & Encodable 的别名
// A type that can convert itself into and out of an external representation.
// public typealias Codable = Decodable & Encodable
structLocation:Codable{varlatitude:Doublevarlongitude:Double}enumAnimal:Int,Codable{case cow =0case dog =1case chicken =2}structFarm:Codable{letname:Stringletlocation:Locationletanimals:[Animal]}letfarm=Farm(name:"Kingcos' Farm",
location:Location(latitude:1.0,
longitude:1.0),
animals:[.cow,.dog,.chicken])
// -> JSON
letpayload:Data=tryJSONEncoder().encode(farm)print(String(data: payload, encoding:.utf8)??"nil")
// JSON ->
letfarmFromJSON=tryJSONDecoder().decode(Farm.self, from: payload)
farmFromJSON.location.latitude
Swift 3.2 vs Swift 4.0
Swift 3.2 兼容旧项目,不需要修改即可构建。
Swift 3.2 不包含 Swift 4.0 中对现有 API 的改进。
Drag & Drop
此处代码摘自视频,未经测试。
// Begin Drag
letdragData=self.data(at: sourceIndexPath)letitemProvider=NSItemProvider(object: dragData)return[UIDragItem(itemProvider: itemProvider)]
// Perform Drop
coordinator.session.loadObjects(ofClass:MyDataType.self){(data)inself.insertData(data, at: destinationIndexPath)
collectionView.reeloadSections(IndexSet(integer:0))}
Large Titles
此处代码摘自视频,未经测试。
// Adopt Large Titles
navigationBar.prefesLargeTitles =true
// Automatically Choose Large Title
navigationItem.largeTitleDisplayMode =.automatic
// Adopt Unified Search Bar
navigationItem.searchController = searchController
macOS
Playground 2.0
Xcode 9
String
Codable
Swift 3.2 vs Swift 4.0
Drag & Drop
Large Titles
HEVC & HEIF
Machine Learning
ARKit
Reference
The text was updated successfully, but these errors were encountered: