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
Make diagnostics for NSCoding classes with unstable names more discouraging.
The diagnostic regarding NSCoding classes with unstable names can be
suppressed by adding @objc (the preferred solution for new code) or
@NSKeyedArchiveLegacy (for existing archives). Provide those as
Fix-Its, in that order.
(Thanks, Jordan!)
Copy file name to clipboardExpand all lines: test/decl/protocol/conforms/nscoding.swift
+12-7Lines changed: 12 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -17,13 +17,15 @@ class CodingA : NSObject, NSCoding {
17
17
// Nested classes
18
18
extensionCodingA{
19
19
classNestedA:NSObject,NSCoding{ // expected-error{{nested class 'CodingA.NestedA' has an unstable name when archiving via 'NSCoding'}}
20
-
// expected-note@-1{{add the '@NSKeyedArchiveLegacy' attribute to specify the class name used for archiving}}{{3-3=@NSKeyedArchiveLegacy("<#class archival name#>")}}
20
+
// expected-note@-1{{for new classes, add '@objc' to specify a unique, prefixed Objective-C runtime name}}{{3-3=@objc(<#Objective-C class name#>)}}
21
+
// expected-note@-2{{for compatibility with existing archives, use '@NSKeyedArchiveLegacy' to record the Swift 3 mangled name}}{{3-3=@NSKeyedArchiveLegacy("<#class archival name#>")}}
21
22
requiredinit(coder:NSCoder){}
22
23
func encode(coder:NSCoder){}
23
24
}
24
25
25
26
classNestedB:NSObject{
26
-
// expected-note@-1{{add the '@NSKeyedArchiveLegacy' attribute to specify the class name used for archiving}}{{3-3=@NSKeyedArchiveLegacy("<#class archival name#>")}}
27
+
// expected-note@-1{{for new classes, add '@objc' to specify a unique, prefixed Objective-C runtime name}}{{3-3=@objc(<#Objective-C class name#>)}}
28
+
// expected-note@-2{{for compatibility with existing archives, use '@NSKeyedArchiveLegacy' to record the Swift 3 mangled name}}{{3-3=@NSKeyedArchiveLegacy("<#class archival name#>")}}
27
29
requiredinit(coder:NSCoder){}
28
30
func encode(coder:NSCoder){}
29
31
}
@@ -62,22 +64,25 @@ extension CodingB {
62
64
63
65
// Fileprivate classes.
64
66
fileprivateclassCodingC:NSObject,NSCoding{ // expected-error{{fileprivate class 'CodingC' has an unstable name when archiving via 'NSCoding'}}
65
-
// expected-note@-1{{add the '@NSKeyedArchiveLegacy' attribute to specify the class name used for archiving}}{{1-1=@NSKeyedArchiveLegacy("<#class archival name#>")}}
67
+
// expected-note@-1{{for new classes, add '@objc' to specify a unique, prefixed Objective-C runtime name}}{{1-1=@objc(<#Objective-C class name#>)}}
68
+
// expected-note@-2{{for compatibility with existing archives, use '@NSKeyedArchiveLegacy' to record the Swift 3 mangled name}}{{1-1=@NSKeyedArchiveLegacy("<#class archival name#>")}}
66
69
requiredinit(coder:NSCoder){}
67
70
func encode(coder:NSCoder){}
68
71
}
69
72
70
73
// Private classes
71
74
privateclassCodingD:NSObject,NSCoding{ // expected-error{{private class 'CodingD' has an unstable name when archiving via 'NSCoding'}}
72
-
// expected-note@-1{{add the '@NSKeyedArchiveLegacy' attribute to specify the class name used for archiving}}{{1-1=@NSKeyedArchiveLegacy("<#class archival name#>")}}
75
+
// expected-note@-1{{for new classes, add '@objc' to specify a unique, prefixed Objective-C runtime name}}{{1-1=@objc(<#Objective-C class name#>)}}
76
+
// expected-note@-2{{for compatibility with existing archives, use '@NSKeyedArchiveLegacy' to record the Swift 3 mangled name}}{{1-1=@NSKeyedArchiveLegacy("<#class archival name#>")}}
73
77
requiredinit(coder:NSCoder){}
74
78
func encode(coder:NSCoder){}
75
79
}
76
80
77
81
// Local classes.
78
82
func someFunction(){
79
83
classLocalCoding:NSObject,NSCoding{ // expected-error{{local class 'LocalCoding' has an unstable name when archiving via 'NSCoding'}}
80
-
// expected-note@-1{{add the '@NSKeyedArchiveLegacy' attribute to specify the class name used for archiving}}{{3-3=@NSKeyedArchiveLegacy("<#class archival name#>")}}
84
+
// expected-note@-1{{for new classes, add '@objc' to specify a unique, prefixed Objective-C runtime name}}{{3-3=@objc(<#Objective-C class name#>)}}
85
+
// expected-note@-2{{for compatibility with existing archives, use '@NSKeyedArchiveLegacy' to record the Swift 3 mangled name}}{{3-3=@NSKeyedArchiveLegacy("<#class archival name#>")}}
@NSKeyedArchiveLegacy("TheCodingG") // expected-error{{@NSKeyedArchiveLegacy may only be used on 'class' declarations}}
115
120
structFoo{}
116
121
117
-
@NSKeyedArchiveLegacy("TheCodingG") // expected-error{{@NSKeyedArchiveLegacy attribute cannot be applied to generic class 'Bar<T>'}}
122
+
@NSKeyedArchiveLegacy("TheCodingG") // expected-error{{'@NSKeyedArchiveLegacy' cannot be applied to generic class 'Bar<T>'}}
118
123
classBar<T>:NSObject{}
119
124
120
125
extensionCodingB{
121
-
@NSKeyedArchiveLegacy("GenericViaParent") // expected-error{{@NSKeyedArchiveLegacy attribute cannot be applied to generic class 'CodingB<T>.GenericViaParent'}}
126
+
@NSKeyedArchiveLegacy("GenericViaParent") // expected-error{{'@NSKeyedArchiveLegacy' cannot be applied to generic class 'CodingB<T>.GenericViaParent'}}
0 commit comments