1

I am trying to store Range objects in a swift collection.

In Obj-C I used to use [NSValue valueWithRange:r];

But this option is not available in swift.

Any idea ?

1 Answer 1

2

You can, see example below

var range1 = Range<Int>(start: 0, end: 100)
var range2 = Range<Int>(start: 100, end: 200)

var array = [range1, range2] // The array type is [Range<Int>]

or if you need NSRange

var range1 = NSRange(location: 0, length: 100)
var range2 = NSRange(location: 100, length: 200)

var array = [range1, range2] // The array type is [_NSRange]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I was trying to set the range as [0...3] instead of 0...3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.