Jeef Jeef - 1 year ago 138
Objective-C Question

Swift Equivalent of removeObjectsInRange:

Having a little trouble tracking down the Swift equivalent of:

//timeArray and locationArray are NSMutableArrays
NSRange removalRange = NSMakeRange(0, i);

[timeArray removeObjectsInRange:removalRange];
[locationArray removeObjectsInRange:removalRange];

I see that Swift does have a call in the API:
typealias NSRange = _NSRange
but I haven't got past that part. Any help?

Answer Source

In addition to Antonio's answer, you can also just use the range operator:

var array = [0, 1, 2, 3, 4, 5]
// array is now [0, 3, 4, 5]
  • The half-closed range operator (1..<3) includes 1, up to but not including 3 (so 1-2).
  • A full range operator (1...3) includes 3 (so 1-3).
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download