Re: short question but I don't know how to describe it
Re: short question but I don't know how to describe it
- Subject: Re: short question but I don't know how to describe it
- From: Marx Bievor <email@hidden>
- Date: Tue, 9 Mar 2010 00:19:42 +0100
Thanks to everyone who answered me. I appreciate your effort.
-M
Am 08.03.2010 um 23:16 schrieb Ed Wynne:
>
> On Mar 8, 2010, at 4:55 PM, Nick Zitzmann wrote:
>> On Mar 7, 2010, at 5:07 PM, Marx Bievor wrote:
>>
>>> I can substitute a String with %@ and an int with %d... like in return @"Hi I am %@ and %d years old", name, age;
>>> what is the right command to substitute a bool and a float? I cannot find any reference at apple's docs.
>>
>> You generally want to use %f for floats and doubles. An ObjC BOOL is a signed 8-bit character type, so %hhd ought to work.
>
> A much better and future-proof (translation: more paranoid) strategy with printf-style format strings, as used by NSString, is to explicitly upcast integer parameters to known compatible types. Ie., for a BOOL or any other type of signed integer use "%d",(int)value instead of relying %hhd that is specific to today's types. Tomorrow when BOOL is changed in some way, the upcast will still work and be just as correct.
>
> -Ed
>
_______________________________________________
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