Page 1 of 1
Getting values from NSIndexSet [RESOLVED]
Posted: Sat Dec 24, 2016 5:56 am
by coder14
How can we get values from an NSIndexSet? From the documentation this is the property:
var supportedMeasurementUnits: NSIndexSet { get }
I have done this:
Code: Select all
s = CocoaMessage(0, fUnit, "supportedMeasurementUnits") ;no error
c = CocoaMessage(0, s, "count") ;returns count
For i = 0 to (c - 1)
v = CocoaMessage(0, CocoaMessage(0, s, "objectAtIndex:", i), "integerValue") ;error!
Next i
but keep getting "Object does not respond to method "objectAtIndex:". I also tried "index:" and "getIndexes:" but they don't work either. I honestly don't know what I'm doing.
Thank you.
Re: Getting values from NSIndexSet
Posted: Sat Dec 24, 2016 6:11 am
by wilbert
coder14 wrote:How can we get values from an NSIndexSet?
I think with PureBasic the easiest way might be to use
getIndexes:maxCount:inIndexRange: or
indexGreaterThanIndex:
Re: Getting values from NSIndexSet
Posted: Sat Dec 24, 2016 6:39 am
by wilbert
Here are two practical examples
Code: Select all
; >> Create mutable index set with indices 5 - 38 <<
range.NSRange\location = 5
range\length = 34
indexSet = CocoaMessage(0, 0, "NSMutableIndexSet indexSetWithIndexesInRange:@", @range)
; >> Shift indexes starting at index 17 <<
CocoaMessage(0, indexSet, "shiftIndexesStartingAtIndex:", 17, "by:", 54)
; >> Show indexes <<
index = CocoaMessage(0, indexSet, "firstIndex")
While index <> #NSNotFound
Debug index
index = CocoaMessage(0, indexSet, "indexGreaterThanIndex:", index)
Wend
Code: Select all
; >> Create mutable index set with indexes 5 - 38 <<
range.NSRange\location = 5
range\length = 34
indexSet = CocoaMessage(0, 0, "NSMutableIndexSet indexSetWithIndexesInRange:@", @range)
; >> Shift indexes starting at index 17 <<
CocoaMessage(0, indexSet, "shiftIndexesStartingAtIndex:", 17, "by:", 54)
; >> Copy indexes to array <<
count = CocoaMessage(0, indexSet, "count")
Dim indexes.i(count - 1)
CocoaMessage(0, indexSet, "getIndexes:", @indexes(), "maxCount:", count, "inIndexRange:", #nil)
; >> Show indexes <<
For i = 0 To count - 1
Debug indexes(i)
Next
Re: Getting values from NSIndexSet
Posted: Sat Dec 24, 2016 6:41 am
by TI-994A
coder14 wrote:How can we get values from an NSIndexSet?
From your snippet, like this:
Code: Select all
s = CocoaMessage(0, fUnit, "supportedMeasurementUnits")
c = CocoaMessage(0, s, "count")
Dim r.i(c - 1)
i = CocoaMessage(0, s,
"getIndexes:", @r(),
"maxCount:", c,
"inIndexRange:", 0)
The array
r() would contain the index values.
Re: Getting values from NSIndexSet
Posted: Sat Dec 24, 2016 8:52 am
by coder14
TI-994A wrote:coder14 wrote:How can we get values from an NSIndexSet?
From your snippet, like this:
Code: Select all
s = CocoaMessage(0, fUnit, "supportedMeasurementUnits")
c = CocoaMessage(0, s, "count")
Dim r.i(c - 1)
i = CocoaMessage(0, s,
"getIndexes:", @r(),
"maxCount:", c,
"inIndexRange:", 0)
The array
r() would contain the index values.
Thanks wilbert! Thanks TI! Looks so simple when its not.
It works btw.