像杜德偉脫掉一樣帥氣,Swift 3把NS脫掉脫掉 !

iOS SDK的Foundation framework十分重要,裡頭定義了許多我們常用的類別。在Swift 3,我們可以更簡單地改用Foundation framework脫掉NS的型別,比方NSURL變成URL,NSDate變成Date。

NSURL -> URLNSDate -> DateNSData -> DataNSIndexPath -> IndexPathNSCharacterSet -> CharacterSetNSNotification -> NotificationNSNotificationCenter -> NotificationCenter

另外有一點值得注意的,這些少了NS的型別,大部分都變成struct定義,所以是value type,不再是原本class定義的reference type。

public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, Hashable, RandomAccessCollection, MutableCollection 

彼得潘的iOS App程式設計入門,文組生的iOS App程式設計入門講師,彼得潘的 Swift 程式設計入門,App程式設計入門作者,http://apppeterpan.strikingly.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store