New features of Swift4.0 (Part I)

The Swift Programming Language (Swift 4)

The 180 introduction of Swift

Range: / / #, a more convenient Range var STR = “Hello playground” var index / / Swift3.0 = str.index (“of:”)! Let greeting = str[str.startIndex..< index] index = str.index (index, offsetBy: 1) / / index let name str[index subscript +1 =..< str.endIndex] = str.index / / Swift4.0 var index1 (“of:”)! Let greeting1 = str.prefix (upTo: index1) index1 = str.index (index1, offsetBy: 1 let name1 str.suffix (from:) = index1 (print) Array (str.enumerated) (print) (Array) (ZIP (1, STR…))) New features of Swift4.0 (Part I)
screenshot.Png


Two, Str a set of types var STR = “Hello, playground” print (str.characters.count) Swift3.0 print (str.count) / / writing / / Swift4.0 / / / is ergodic str.forEach {$0} New features of Swift4.0 (Part I)
multiple lines of text (“plist”) format let / / / plistInfo = “&lt”; XML? Version= “1” encoding= “UTF-8” > < plist? Version= “1” > < array> < dict> < key> title< /key> < string> /string > &lt WiFi<; key> imageName< /key> < string> serversSet< /string> < /dict> < /array> < /plist> “JSON let jsonInfo” / / / format = “{” data “: {” title “:” String is a “collection” author “:” 23 “creat_at”” “2017-06-13”,}, “”, “print (plistInfo), print (jsonInfo), New features of Swift4.0 (Part I)
, print result.Png.”


Three, improved access to private / #: improved private access (extensions can access the private modified variables) class Person fileprivate var name: {String = “MG” private var age extension Person {func = 23} (change) {name = “clearly” age = 32}} let person = Person (person.change) (New features of Swift4.0 (Part I))
screenshot.Png


Four, more intelligent security Key Coding / / Value: Key Value # intelligent safety Coding class Weather: NSObject @objc var @objc {months = 12 var season = “Spring” @objc var seasones = “Spring”, “Summer”, “Autumn”; “winter” before Swift4 let]} / / / writing w = Weather (w.season) = “Summer” var season = w.value (“forKeyPath: season”) w.setValue (“Autumn forKeyPath:”, “season”) Swift4.0 let /Weather.season var / / / seasonKeyPath = Season1 w[keyPath: = seasonKeyPath] w[keyPath: seasonKeyPath] = “MG New features of Swift4.0 (Part I)
.Png screenshot shows clearly”