Forum Navigation
You need to log in to create posts and topics.

Re: Getting the Max number from a set of numbers

Posted by: paboyle1703 <paboyle1703@...>

This is an adaptation of code from the Example folder, clunky but works, I'm sure there'll be more elegant solutions forthcoming 



include "NSLog.incl"

local fn MyComparator( os as OrderedSetRef, obj1 as CFTypeRef, obj2 as CFTypeRef ) as NSComparisonResult
'~'1
NSLog(@"%@,%@",obj1,obj2)
NSComparisonResult result = fn StringCompare( obj1, obj2 )

end fn = result


void local fn DoIt
'~'1
OrderedSetRef os = fn OrderedSetWithArray( @[@2,@44,@11,@99,@35] )

NSLog(@"%@n",os)

CFArrayRef array = fn OrderedSetSortedArrayUsingComparator( os, @fn MyComparator, NULL )
NSUinteger count = fn ArrayCount(Array)

NSLog(@"n%@ count= %d",array, count)
NSLog(@"Max Number= %@", fn ArrayObjectAtIndex( array, count-1))

end fn

fn DoIt

HandleEvents

On Apr 4, 2022, at 22:07, Rich Love <[email protected]> wrote:


The following works in Objective-C
But how is this done in FutureBasic? (without using a C Function)
 
NSArray *unsortedArray = @[ @2, @44, @11, @99, @35 ];
NSNumber *maxNumber = [unsortedArray valueForKeyPath:@"@max.self"];
NSLog(@"%@", maxNumber); // 99
 
 
Rich
 
 
 
Carnation Software
 
MacWise Terminal emulation for Macintosh
512 858-9234
 


--
To unsubscribe, send ANY message to: [email protected] To access the list archives, go to:  http://freegroups.net/groups/futurebasic/


Peter Boyle
FB 7.0.12
OSX 10.14.6
Xcode 10.2
iMac 21.5 Late 2015 
2.8 GHz Intel Core i5


































--
To unsubscribe, send ANY message to: [email protected] To access the list archives, go to: http://freegroups.net/groups/futurebasic/