It is currently Sun Apr 23, 2017 10:42 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Getting values from NSIndexSet [RESOLVED]
PostPosted: Sat Dec 24, 2016 5:56 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Jun 21, 2011 10:39 am
Posts: 325
How can we get values from an NSIndexSet? From the documentation this is the property:

var supportedMeasurementUnits: NSIndexSet { get }

I have done this:
Code:
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.

Top
 Profile  
Reply with quote  
 Post subject: Re: Getting values from NSIndexSet
PostPosted: Sat Dec 24, 2016 6:11 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 2812
Location: Netherlands
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:

_________________
MacOS 10.12, PB 5.51 x64


Last edited by wilbert on Sat Dec 24, 2016 6:45 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Getting values from NSIndexSet
PostPosted: Sat Dec 24, 2016 6:39 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 2812
Location: Netherlands
Here are two practical examples
Code:
; >> 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:
; >> 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

_________________
MacOS 10.12, PB 5.51 x64


Last edited by wilbert on Sat Dec 24, 2016 6:44 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Getting values from NSIndexSet
PostPosted: Sat Dec 24, 2016 6:41 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 1936
coder14 wrote:
How can we get values from an NSIndexSet?

From your snippet, like this:
Code:
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 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!


Top
 Profile  
Reply with quote  
 Post subject: Re: Getting values from NSIndexSet
PostPosted: Sat Dec 24, 2016 8:52 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Jun 21, 2011 10:39 am
Posts: 325
TI-994A wrote:
coder14 wrote:
How can we get values from an NSIndexSet?

From your snippet, like this:
Code:
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye