@@ -3,6 +3,55 @@ Note: This is in reverse chronological order, so newer entries are added to the
3
3
Swift 3.0
4
4
---------
5
5
6
+ * [ SE-0112] ( https://github.com/apple/swift-evolution/blob/master/proposals/0112-nserror-bridging.md ) :
7
+ The ` NSError ` type is now bridged to the Swift ` Error ` protocol type
8
+ (formerly called ` ErrorProtocol ` in Swift 3, ` ErrorType ` in Swift 2)
9
+ in Objective-C APIs, much like other Objective-C types are
10
+ bridged to Swift (e.g., ` NSString ` being bridged to ` String ` ). For
11
+ example, the ` UIApplicationDelegate ` method
12
+ ` applicate(_:didFailToRegisterForRemoteNotificationsWithError:) `
13
+ changes from accepting an ` NSError ` argument:
14
+
15
+ ``` swift
16
+ optional func application (_ application : UIApplication, didFailToRegisterForRemoteNotificationsWithError error : NSError)
17
+ ```
18
+
19
+ to accepting an ` Error ` argument:
20
+
21
+ ``` swift
22
+ optional func application (_ application : UIApplication, didFailToRegisterForRemoteNotificationsWithError error : Error )
23
+ ```
24
+
25
+ Additionally, error types imported from Cocoa[ Touch] maintain all of
26
+ the information in the corresponding ` NSError ` , so it is no longer
27
+ necessary to ` catch let as NSError ` to extract (e.g.) the user-info
28
+ dictionary. Specific also error types contain typed accessors for
29
+ their common user-info keys. For example:
30
+
31
+ ``` swift
32
+ catch let error as CocoaError where error.code == .fileReadNoSuchFileError {
33
+ print (" No such file: \( error.url ) " )
34
+ }
35
+ ```
36
+
37
+ Finally, Swift-defined error types can provide localized error
38
+ descriptions by adopting the new ` LocalizedError ` protocol, e.g.,
39
+
40
+ ``` swift
41
+ extension HomeworkError : LocalizedError {
42
+ var errorDescription: String ? {
43
+ switch self {
44
+ case .forgotten : return NSLocalizedString (" I forgot it" )
45
+ case .lost : return NSLocalizedString (" I lost it" )
46
+ case .dogAteIt : return NSLocalizedString (" The dog ate it" )
47
+ }
48
+ }
49
+ }
50
+ ```
51
+
52
+ Similarly, the new ` RecoverableError ` and ` CustomNSError ` protocols
53
+ allow additional control over the handling of the error.
54
+
6
55
* [ SE-0060] ( https://github.com/apple/swift-evolution/blob/master/proposals/0060-defaulted-parameter-order.md ) :
7
56
Function parameters with default arguments must now be specified in
8
57
declaration order. A call site must always supply the arguments it provides
0 commit comments