Re: Learning Cocoa/ObjectiveC and wondering why I had to do this.
Re: Learning Cocoa/ObjectiveC and wondering why I had to do this.
- Subject: Re: Learning Cocoa/ObjectiveC and wondering why I had to do this.
- From: Jeremy French <email@hidden>
- Date: Sun, 6 Mar 2005 18:51:19 -0500
The following declares a pointer named "result" that will point to a NSString object:
NSString *result
You create an NSString object instance for result to point to, when you send the following message to the NSString class:
[NSString stringWithFormat:@"%@ has %u letters.",string,letterCount];
One way to insert information into a string is to use the class method "stringWithFormat:" with special placeholders. In the case above, you are creating a string that will read something like this: "<string> has <letterCount> letters.", where <string> is replaced by the actual string value and <letterCount is replaced by the value of letterCount.
To view a list of these placeholders, see <http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/index.html#//apple_ref/doc/uid/10000035i>.
You can bring up documentation for a method by holding down the option key, and double clicking the method name. XCode help will then display documentation for that method. So, to display documentation for the "stringWithFormat:" method, just hold down the option key and double click on "stringWithFormat:".
For more information NSString messages, see:
<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSString.html#//apple_ref/occ/cl/NSString>.
---
On Mar 6, 2005, at 5:20 PM, Tom Boucher wrote:
Can you translate this for me?
NSString *result = [NSString stringWithFormat:@"%@ has %u letters.",string,letterCount];
It did what I wanted, which was create a string that is the results of a string, an unsigned int and some other words and put them in there.
But it didn't do it the way I thought I should. I can't figure out why I had to put the NSString inside the object call [NSString stringWithFormat...]
Was doing the challenge in that one Big Nerd Ranch cocoa book and got lost a bit.
My C skills are rusty, it's been a few years. So I apologize for the blatant newb post. _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden