Getting values from NSIndexSet [RESOLVED]

Mac OSX specific forum
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Getting values from NSIndexSet [RESOLVED]

Post 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. :shock:
Last edited by coder14 on Sun Jan 08, 2017 5:53 am, edited 1 time in total.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Getting values from NSIndexSet

Post 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:
Last edited by wilbert on Sat Dec 24, 2016 6:45 am, edited 1 time in total.
Windows (x64)
Raspberry Pi OS (Arm64)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Getting values from NSIndexSet

Post 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
Last edited by wilbert on Sat Dec 24, 2016 6:44 am, edited 1 time in total.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Getting values from NSIndexSet

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Getting values from NSIndexSet

Post 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. :oops:

It works btw. :D
Post Reply