Re: understanding conversions between CF and NS datatypes
Re: understanding conversions between CF and NS datatypes
- Subject: Re: understanding conversions between CF and NS datatypes
- From: Negm-Awad Amin <email@hidden>
- Date: Thu, 4 Sep 2008 16:46:54 +0200
Am Do,04.09.2008 um 16:41 schrieb Negm-Awad Amin:
Am Sa,30.08.2008 um 05:22 schrieb Michael Ash:
On Fri, Aug 29, 2008 at 1:38 PM, Allen Curtis
<email@hidden> wrote:
1. Where can I get a better understanding of the data conversion
between
these different frameworks?
2. Ultimately the device path names will appear in a ComboBox. Was
it
necessary to convert the CFMutableArray to a NSMutableArray for the
datasource function?
Ultimately the most important thing to understand about toll-free
bridging (the link between CF and NS data types) is that you don't
have to convert anything. You *can't* convert anything. Because they
aren't two different things. An NSArray *is* a CFArray. An
NSMutableArray is a CFMutableArray. They are just two different names
for the same type.
I'm not sure, whether this is completly correct. I would prefer to
say, that are two different names of two different types, which are
interchangeable. But AFAIK in some (rare) cases, CF and NS behaves
differently. I know this example
CFArrayCreateMutable
Creates a new empty mutable array.
…
capacity
*The maximum number of values that can be contained* by the new
array. The array starts empty and can grow to this number of values
(and it can have less). If this parameter is 0, the array’s maximum
capacity is not limited. The value must not be negative.
…
arrayWithCapacity:
…
numItems
The *initial capacity* of the new array.
…
Discussion
Mutable arrays *expand as needed*; numItems simply establishes the
object’s initial capacity.
So, if you get an CFMutableArray and cast it to an NSMutableArray
you will get unintended results on inserting behind the capacity.
Cheers,
Amin
Oh, I tried it (Casting an CFMutableArray to an NSMutablearray and
send masses of -addObject: to it) and did not get an error?
Can somebody explain that?
Cheers,
Amin
It gets slightly tricky because the compiler doesn't know this
crucial
fact. So when you have a CFMutableArrayRef and you try to treat it
like it was an NSMutableArray*, the compiler gets complainey. So you
have to do some fancy typecasting to shut it up. But it's very
important to understand that this typecast doesn't do any sort of
conversion or translation or anything of the sort, it just tells the
compiler to look at the exact same pointer to the exact same object
in
a new light.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Amin Negm-Awad
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Amin Negm-Awad
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden