Skip to content

Commit 2555445

Browse files
committed
Discuss ObjC generic import support in changelog.
1 parent ca096a2 commit 2555445

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,54 @@
11
Note: This is in reverse chronological order, so newer entries are added to the top.
22

33
Swift 3.0
4-
-------
4+
---------
5+
6+
* [SE-0057](https://github.com/apple/swift-evolution/blob/master/proposals/0057-importing-objc-generics.md):
7+
Objective-C lightweight generic classes are now imported as generic types
8+
in Swift. Because Objective-C generics are not represented at runtime,
9+
there are some limitations on what can be done with them in Swift:
10+
11+
- If an ObjC generic class is used in a checked `as?`, `as!`, or `is` cast,
12+
the generic parameters are not checked at runtime. The cast succeeds if the
13+
operand is an instance of the ObjC class, regardless of parameters.
14+
15+
```swift
16+
let x = NSFoo<NSNumber>(value: NSNumber(integer: 0))
17+
let y: AnyObject = x
18+
let z = y as! NSFoo<NSString> // Succeeds
19+
```
20+
21+
- Swift subclasses can only inherit an ObjC generic class if its generic
22+
parameters are fully specified.
23+
24+
```swift
25+
// Error: Can't inherit ObjC generic class with unbound parameter T
26+
class SwiftFoo1<T>: NSFoo<T> { }
27+
28+
// OK: Can inherit ObjC generic class with specific parameters
29+
class SwiftFoo2<T>: NSFoo<NSString> { }
30+
```
31+
32+
- Swift can extend ObjC generic classes, but the extensions cannot be
33+
constrained, and definitions inside the extension do not have access to
34+
the class's generic parameters.
35+
36+
```swift
37+
extension NSFoo {
38+
// Error: Can't access generic param T
39+
func foo() -> T {
40+
return T()
41+
}
42+
}
43+
44+
// Error: extension can't be constrained
45+
extension NSFoo where T: NSString {
46+
}
47+
```
48+
49+
- Foundation container classes `NS[Mutable]Array`, `NS[Mutable]Set`, and
50+
`NS[Mutable]Dictionary` are still imported as nongeneric classes for
51+
the time being.
552

653
* As part of the changes for SE-0055 (see below), the *pointee* types of
754
imported pointers (e.g. the `id` in `id *`) are no longer assumed to always

0 commit comments

Comments
 (0)