FROM : Joachim Haagen Bøe
DATE : Sat Nov 09 18:13:01 2002
Thanks for all your reply guys and girls! That was really helpful!
Cheers,
Joachim
On Saturday, November 9, 2002, at 11:41 PM, Andreas H=F6schler wrote:
> Hi,
>
>> Question 1 - pointers
>>
>> I understand that * means the the variable is a pointer, and to me it =
=20
>> seems as if ALL complex variables are pointers (im up to chapter 4 in =
=20
>> the book). Is this the case?
>
> Yes!. If you allocate an object - e.g. NSString *string =3D =20
> [[NSMutableString alloc] init]; - ram space for the object is =20
> allocated (usually only a few bytes) and a pointer to this space is =20=
> returned. This pointer is used to address the object. This pointer is =20=
> also the target for messages, e.g. int length =3D [string length]. =
This =20
> corresponds to string.length in Java.
>
>> And is passing a pointer as a parameter to a method the same as =20
>> passing a complex variable to a method in Java ?
>
> Yes!
>
>> Question 2 - @, %, %@ and %d
>>
>> When creating NSStrings I see a lot of these symbols. I have figured =20=
>> out that you specify which variables go into these symbols, but have =20=
>> the following question regarding the following code:
>>
>> outputString =3D [NSString stringWithFormat:@"%@ has %d letters", =20
>> inputString, [inputString length]];
>>
>> What is the very first @ for?
>> Why is the second %@, and not $d ?
>
> The second is %d and the first is %@, right?
>
>> What is the difference between %@ and %d ?
>
> %d is a placeholder for int, unsigned,... %@ is a placeholder for an =20=
> Objective-C object. This object is automatically send the message =20
> "description" which is supposed to return an NSString. So you can pass =
=20
> NSNumber, NSDeciamlNumber, NSString,... (all objects that respond to =20=
> description) as a parameter for a %@ placeholder.
>
>> Okay, thats my main difficoulties, other than the whole [] instead of =
=20
>> .'s in the notation.
>
> ... which is genial by the way. Consider the following method of =20
> NSCalendarDate.
>
> - (NSCalendarDate *)dateByAddingYears:(int)year months:(int)month =20
> days:(int)day hours:(int)hour minutes:(int)minute seconds:(int)second
>
> You call it as follows.
>
> NSCalendarDate *date; // Assume this object exists
>
> [date dateByAddingYears:0 months:3 days:15 hours:2 minutes:30 =20=
> seconds:0];
>
> Try this in Java or C++. It would look like.
>
> =20
> =
date.dateByAddingSomeStuffNoBodyKnowsHowToCallThisMethod(0,3,15,2,30,0)=20=
> ;
>
> What is easier to read?
>
>> Im sorry about the very basic questions, but I'd appreciate if anyone =
=20
>> took the time out of their busy schedual to answer some of these.
>
> You are welcome!
>
> Regards,
>
> Andreas
DATE : Sat Nov 09 18:13:01 2002
Thanks for all your reply guys and girls! That was really helpful!
Cheers,
Joachim
On Saturday, November 9, 2002, at 11:41 PM, Andreas H=F6schler wrote:
> Hi,
>
>> Question 1 - pointers
>>
>> I understand that * means the the variable is a pointer, and to me it =
=20
>> seems as if ALL complex variables are pointers (im up to chapter 4 in =
=20
>> the book). Is this the case?
>
> Yes!. If you allocate an object - e.g. NSString *string =3D =20
> [[NSMutableString alloc] init]; - ram space for the object is =20
> allocated (usually only a few bytes) and a pointer to this space is =20=
> returned. This pointer is used to address the object. This pointer is =20=
> also the target for messages, e.g. int length =3D [string length]. =
This =20
> corresponds to string.length in Java.
>
>> And is passing a pointer as a parameter to a method the same as =20
>> passing a complex variable to a method in Java ?
>
> Yes!
>
>> Question 2 - @, %, %@ and %d
>>
>> When creating NSStrings I see a lot of these symbols. I have figured =20=
>> out that you specify which variables go into these symbols, but have =20=
>> the following question regarding the following code:
>>
>> outputString =3D [NSString stringWithFormat:@"%@ has %d letters", =20
>> inputString, [inputString length]];
>>
>> What is the very first @ for?
>> Why is the second %@, and not $d ?
>
> The second is %d and the first is %@, right?
>
>> What is the difference between %@ and %d ?
>
> %d is a placeholder for int, unsigned,... %@ is a placeholder for an =20=
> Objective-C object. This object is automatically send the message =20
> "description" which is supposed to return an NSString. So you can pass =
=20
> NSNumber, NSDeciamlNumber, NSString,... (all objects that respond to =20=
> description) as a parameter for a %@ placeholder.
>
>> Okay, thats my main difficoulties, other than the whole [] instead of =
=20
>> .'s in the notation.
>
> ... which is genial by the way. Consider the following method of =20
> NSCalendarDate.
>
> - (NSCalendarDate *)dateByAddingYears:(int)year months:(int)month =20
> days:(int)day hours:(int)hour minutes:(int)minute seconds:(int)second
>
> You call it as follows.
>
> NSCalendarDate *date; // Assume this object exists
>
> [date dateByAddingYears:0 months:3 days:15 hours:2 minutes:30 =20=
> seconds:0];
>
> Try this in Java or C++. It would look like.
>
> =20
> =
date.dateByAddingSomeStuffNoBodyKnowsHowToCallThisMethod(0,3,15,2,30,0)=20=
> ;
>
> What is easier to read?
>
>> Im sorry about the very basic questions, but I'd appreciate if anyone =
=20
>> took the time out of their busy schedual to answer some of these.
>
> You are welcome!
>
> Regards,
>
> Andreas
| Related mails | Author | Date |
|---|---|---|
| Joachim Haagen Bøe | Nov 9, 05:14 | |
| Jon Johnson | Nov 9, 05:40 | |
| Andreas Höschler | Nov 9, 05:42 | |
| Fabien Roy | Nov 9, 08:51 | |
| Sanjay Samani | Nov 9, 09:32 | |
| Richard | Nov 9, 17:14 | |
| Hasan Diwan | Nov 9, 18:01 | |
| Joachim Haagen Bøe | Nov 9, 18:13 |






Cocoa mail archive

