[futurebasic] Re: [FB] New FB functionality in 7.0.11

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2022 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kashmidheiser@...>
Date: Fri, 28 Jan 2022 17:50:45 -0500
Rich asked:

> I have no experience with dictionaries.
> I added a few lines to print the value of Size and it works.
> But Size is a CFTypeRef.
> How do you convert that to a string or integer so you can compare the results?


Dictionaries are wonderful, but they can be a little cumbersome when it comes to retrieving numbers.

Their advantage is the ability to retrieve information simply by using the key, which is a CFString.

Here's how to handle a number.


void local fn testDict

window 1,, (0,0,550,400)

CFDictionaryRef dict = @{
@"Volume is":@11,
@"Height inches":@71,

print dict


   Pertinent information is in the CocoaUI Value.incl header.
   @12 is the literal shortcut for fn NumberWithInteger( 12 ) which creates a CFNumberRef.

   Since the resulting CFNumberRef is assigned to the dictionary key @"Size",
   we can retrieve it from the dictionary using:

      CFNumberRef sizeRef = fn DictionaryObjectForKey( dict, @"Size" ) 

   To convert the CFNumberRef back to an NSInteger use:

      NSInteger size = fn NumberIntegerValue( sizeRef )
     Here it is wrapped toegether:

print @"The size is "; fn NumberIntegerValue( fn DictionaryObjectForKey( dict, @"Size" ) ); @"."

end fn

fn testDict