Skip to content

Commit 9369c4e

Browse files
committed
SpriteKit overlay: remove the subscript from SKNode
In iOS 8.0/OS X 10.10, SpriteKit introduced an -objectForKeyedSubscript: method that enabled subscripting in Objective-C. However, this subscript wasn't generally useful in Swift because it took AnyObject and produced AnyObject, so the SpriteKit overlay defined a subscript that took a String and produced an [SKNode]. Subsequently, in iOS 9.0/OS X 10.10, -objectForKeyedSubscript: got type annotations that gave it the appropriate Swift signature, which made the subscript defined in the overlay redundant. The twisty logic of the Clang importer would suppress the imported subscript when it saw the one in the overlay, hiding the redundancy. My cleanup of that logic in 0c0a0fa caused uses of the subscript to be redundant. Removal of the redundant code in the overlay is the overall best answer, because it minimizes the size of the overlay and leaves the API in the Objective-C header. However, this will introduce a regression for SpriteKit applications targeting iOS 7.0/OS X 10.8, where the overlay was compensating for the lack of this operation before iOS 8.0 / OS X 10.8. There are workarounds here we can investigate, although they're fairly hacky.
1 parent 3e7d9de commit 9369c4e

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

stdlib/public/SDK/SpriteKit/SpriteKit.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,3 @@ public typealias SKColor = UIColor
1515
override init() { _sanityCheckFailure("don't touch me") }
1616
@objc func _copyImageData() -> NSData! { return nil }
1717
}
18-
19-
extension SKNode {
20-
public subscript (name: String) -> [SKNode] {
21-
// Note: Don't stomp on objectForKeyedSubscript:
22-
@objc(_swiftObjectForKeyedSubscript:) get {
23-
var nodes = [SKNode]()
24-
enumerateChildNodesWithName(name) { node, stop in
25-
nodes.append(node)
26-
}
27-
28-
return nodes
29-
}
30-
}
31-
}
32-

test/1_stdlib/SpriteKit.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
import Foundation
1010
import SpriteKit
1111

12+
// Check that the subscript is there.
13+
@available(OSX,introduced=10.10)
14+
@available(iOS,introduced=8.0)
15+
@available(tvOS,introduced=8.0)
16+
@available(watchOS,introduced=2.0)
17+
func testSubscript(node: SKNode) {
18+
var nodes: [SKNode] = node["me"]
19+
}
20+
1221
// SKColor is NSColor on OS X and UIColor on iOS.
1322

1423
var r = CGFloat(0)

0 commit comments

Comments
 (0)