1
1
// This source file is part of the Swift.org open source project
2
2
//
3
- // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
3
+ // Copyright (c) 2014 - 2016, 2018 Apple Inc. and the Swift project authors
4
4
// Licensed under Apache License v2.0 with Runtime Library Exception
5
5
//
6
- // See http ://swift.org/LICENSE.txt for license information
7
- // See http ://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
6
+ // See https ://swift.org/LICENSE.txt for license information
7
+ // See https ://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8
8
//
9
9
10
10
11
11
open class NSIndexPath : NSObject , NSCopying , NSSecureCoding {
12
12
13
- internal var _indexes : [ Int ]
13
+ private var _indexes : [ Int ]
14
+
14
15
override public init ( ) {
15
16
_indexes = [ ]
16
17
}
17
- public init ( indexes: UnsafePointer < Int > ! , length: Int ) {
18
- _indexes = Array ( UnsafeBufferPointer ( start: indexes, count: length) )
18
+
19
+ public init ( indexes: UnsafePointer < Int > ? , length: Int ) {
20
+ if length == 0 {
21
+ _indexes = [ ]
22
+ } else {
23
+ _indexes = Array ( UnsafeBufferPointer ( start: indexes!, count: length) )
24
+ }
19
25
}
20
26
21
27
private init ( indexes: [ Int ] ) {
@@ -26,7 +32,10 @@ open class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
26
32
return copy ( with: nil )
27
33
}
28
34
29
- open func copy( with zone: NSZone ? = nil ) -> Any { NSUnimplemented ( ) }
35
+ open func copy( with zone: NSZone ? = nil ) -> Any {
36
+ return self
37
+ }
38
+
30
39
public convenience init ( index: Int ) {
31
40
self . init ( indexes: [ index] )
32
41
}
@@ -44,6 +53,7 @@ open class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
44
53
open func adding( _ index: Int ) -> IndexPath {
45
54
return IndexPath ( indexes: _indexes + [ index] )
46
55
}
56
+
47
57
open func removingLastIndex( ) -> IndexPath {
48
58
if _indexes. count <= 1 {
49
59
return IndexPath ( indexes: [ ] )
@@ -55,6 +65,7 @@ open class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
55
65
open func index( atPosition position: Int ) -> Int {
56
66
return _indexes [ position]
57
67
}
68
+
58
69
open var length : Int {
59
70
return _indexes. count
60
71
}
@@ -71,7 +82,12 @@ open class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
71
82
indexes. advanced ( by: pos) . pointee = idx
72
83
}
73
84
}
74
-
85
+
86
+ @available ( * , unavailable, renamed: " getIndex(_:range:) " )
87
+ open func getIndexes( _ indexes: UnsafeMutablePointer < Int > ) {
88
+ NSUnsupported ( )
89
+ }
90
+
75
91
// comparison support
76
92
// sorting an array of indexPaths using this comparison results in an array representing nodes in depth-first traversal order
77
93
open func compare( _ otherObject: IndexPath ) -> ComparisonResult {
@@ -96,10 +112,6 @@ open class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
96
112
}
97
113
}
98
114
99
- extension NSIndexPath {
100
- open func getIndexes( _ indexes: UnsafeMutablePointer < Int > ) { NSUnimplemented ( ) }
101
- }
102
-
103
115
104
116
extension NSIndexPath : _StructTypeBridgeable {
105
117
public typealias _StructType = IndexPath
0 commit comments