ObjectiveC and Declares

Can anyone clarify in the apple docs what the asterisk would mean in the following:

Class NSClassFromString ( NSString *aClassName );

but not in:

BOOL NSContainsRect ( NSRect aRect, NSRect bRect );

It means it’s a pointer to the data and not the actual data.

So in NSClassFromString why would this be a pointer rather than just passing a string to the function?

Use CFStringRef. So the declare would be:

Declare Function NSClassFromString lib "Cocoa.framework" (className as CFStringRef) as Ptr

Since CFStringRef does implicit conversion from/to string, you can simply pass in the class name as a standard Xojo string, i.e.:

dim NSObjectClassRef as Ptr = NSClassFromString("NSObject")

[quote=120445:@Jason King]Use CFStringRef. So the declare would be:

Declare Function NSClassFromString lib "Cocoa.framework" (className as CFStringRef) as Ptr

Since CFStringRef does implicit conversion from/to string, you can simply pass in the class name as a standard Xojo string, i.e.:

dim NSObjectClassRef as Ptr = NSClassFromString("NSObject")

Thanks Jason. Just wondering from ObjectiveC point of view though why it would be a pointer to the class name though and not just the class name.

Ah, I misunderstood what you were asking. From my understanding it is because NSRects are a datatype and not a class, and are therefore passed byVal (not as a pointer), while NSString is a class so instances are passed byRef (as a pointer). The same is true in Xojo: integers, doubles, strings, and other datatypes are passed byVal, while classes are passed byRef even when you do not specify that in a method. Hopefully that makes sense?

Mostly because strings are variable in length and you must pass a fixed size variable as a parameter. Thus you pass the pointer. NSRect is fixed size and can be passed directly.

I see, thanks Tim

Tim what about (void *) as a return value.

For void * use Ptr (it is a pointer to an unknown type).