11// This source file is part of the Swift.org open source project
22//
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
44// Licensed under Apache License v2.0 with Runtime Library Exception
55//
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
88//
99
1010
1111open class NSIndexPath : NSObject , NSCopying , NSSecureCoding {
1212
13- internal var _indexes : [ Int ]
13+ private var _indexes : [ Int ]
14+
1415 override public init ( ) {
1516 _indexes = [ ]
1617 }
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+ }
1925 }
2026
2127 private init ( indexes: [ Int ] ) {
@@ -26,7 +32,10 @@ open class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
2632 return copy ( with: nil )
2733 }
2834
29- open func copy( with zone: NSZone ? = nil ) -> Any { NSUnimplemented ( ) }
35+ open func copy( with zone: NSZone ? = nil ) -> Any {
36+ return self
37+ }
38+
3039 public convenience init ( index: Int ) {
3140 self . init ( indexes: [ index] )
3241 }
@@ -44,6 +53,7 @@ open class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
4453 open func adding( _ index: Int ) -> IndexPath {
4554 return IndexPath ( indexes: _indexes + [ index] )
4655 }
56+
4757 open func removingLastIndex( ) -> IndexPath {
4858 if _indexes. count <= 1 {
4959 return IndexPath ( indexes: [ ] )
@@ -55,6 +65,7 @@ open class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
5565 open func index( atPosition position: Int ) -> Int {
5666 return _indexes [ position]
5767 }
68+
5869 open var length : Int {
5970 return _indexes. count
6071 }
@@ -71,7 +82,12 @@ open class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
7182 indexes. advanced ( by: pos) . pointee = idx
7283 }
7384 }
74-
85+
86+ @available ( * , unavailable, renamed: " getIndex(_:range:) " )
87+ open func getIndexes( _ indexes: UnsafeMutablePointer < Int > ) {
88+ NSUnsupported ( )
89+ }
90+
7591 // comparison support
7692 // sorting an array of indexPaths using this comparison results in an array representing nodes in depth-first traversal order
7793 open func compare( _ otherObject: IndexPath ) -> ComparisonResult {
@@ -96,10 +112,6 @@ open class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
96112 }
97113}
98114
99- extension NSIndexPath {
100- open func getIndexes( _ indexes: UnsafeMutablePointer < Int > ) { NSUnimplemented ( ) }
101- }
102-
103115
104116extension NSIndexPath : _StructTypeBridgeable {
105117 public typealias _StructType = IndexPath
0 commit comments