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: "Michael Ash" <email@hidden>
- Date: Fri, 5 Sep 2008 07:52:54 -0400
On Fri, Sep 5, 2008 at 3:24 AM, Negm-Awad Amin <email@hidden> wrote:
>
> Am Do,04.09.2008 um 20:20 schrieb Michael Ash:
>
>> On Thu, Sep 4, 2008 at 1:40 PM, Negm-Awad Amin <email@hidden>
>> wrote:
>>>
>>> Am Do,04.09.2008 um 18:27 schrieb Michael Ash:
>>>
>>>> On Thu, Sep 4, 2008 at 10:41 AM, Negm-Awad Amin <email@hidden>
>>>> wrote:
>>>>>
>>>>> Am Sa,30.08.2008 um 05:22 schrieb Michael Ash:
>>>>>
>>>>>> 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.
>>>>
>>>> No, they are the same type.
>>>>
>>>>> But AFAIK in some (rare) cases, CF and NS behaves differently.
>>>>
>>>> Meaningless. You can subclass NSArray and get whatever behavior you
>>>> want. The result is still an NSArray (and still a CFArray).
>>>
>>> But I wouldn't say, that a subclass of a baseclass is the same type as
>>> the
>>> baseclass. You can assign a subclass instacne to a baseclass pointer and
>>> there is no casting, so indeed the situation is similiar to NSArray and
>>> CFArray.
>>
>> Subclassing is supposed to be an "is a" relationship. In other words,
>> if I subclass NSMutableArray and call the new class a MyMutableArray,
>> then a MyMutableArray is an NSMutableArray. An NSMutableArray is in
>> turn an NSArray, and an NSArray is an NSObject.
>>
>> Likewise, an NSArray is a CFArray, and a CFArray is an NSArray. They
>> are just two different names for the same thing. The fact that you can
>> obtain different behaviors depending on how you create them is not all
>> that interesting, as that happens *anyway* with many different
>> classes.
>
> I completly agree, that an instance of a subclass "is a(n)" instance of the
> baseclass. No doubt.
> But, if I understood you correct, you said that the subclass and a baseclass
> are the same type (as CFArray and NSArray are). Since type is a formal term,
> I do not agree with this statement.
> Of course, with subclassing the term type became more shaded. But I think,
> that there is still a formal meaning of it.
Well, are we talking about compile time or run time?
If you mean compile time then sure, they're not the same. That is,
after all, why you need to cast them to avoid warnings.
But at run time they are the same type. If you disagree, just create
an NSArray and a CFArray (with the standard CFType callbacks) and try
to tell the difference between them!
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