Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
I am confused by the syntax below for the parts in bold:
-(void)someAction: (NSString *)str[B];[/B]
I am confused as to why the "*" is in the paranthesis and the "str" variable is not. I understand pointers but again it is the layout that I am not getting in this case.
I am confused by the syntax below for the parts in bold:
-(void)someAction: (NSString *)str[B];[/B]
I am confused as to why the "*" is in the paranthesis and the "str" variable is not. I understand pointers but again it is the layout that I am not getting in this case.
Thanks for any help.
When you write something like: int number; it means that number is of type int
In the same way, when you have something like: int *number; Its better look at it like number is of type "int *" which of course means integer pointer. Even though the star is right before the variable name it actually is a "part of the type" if I can put it that way.
Hence for the above reason you see it as: (NSString *)str where the type of the parameter is in the parenthesis and the name is outside.
When you write something like: int number; it means that number is of type int
In the same way, when you have something like: int *number; Its better look at it like number is of type "int *" which of course means integer pointer. Even though the star is right before the variable name it actually is a "part of the type" if I can put it that way.
Hence for the above reason you see it as: (NSString *)str where the type of the parameter is in the parenthesis and the name is outside.
So it is the same right ?
int number int *number (a integer pointer) (int *)number ( the same as the above) (i dont know if this is possible)
int number int *number (a integer pointer) (int *)number ( the same as the above) (i dont know if this is possible)
If by same you mean that it conveys the same information related to the type of "number" then yes...But you'd use
int *number
and
(int *)number
in two very different situations.
When you write int *number you are basically defining a variable that is an integer pointer.
void doSomething() { int *number = NULL; ... }
You write (int *)number when you are declaring/defining an Objective C method to specify that your method takes an integer pointer as a parameter
-(void) doSomethingUsing:(int *)number { ... }
The other situation where you'd see something like (int *)number is when you are doing a C style type cast..which is basically changing the type of a variable (if you don't already know that)
It has to do with the placement of the "*" symbol, as you know the"*" means a pointer to something. What is confusing is a lot of times we type our declaration like this this: NSString *myString; so makes it look like the"*" is part of myString rather then NSString while it is clearer if you type NSString* myString. this way makes NSString* looks as a whole. When I first started Obj-C, I was a bit puzzled by this as well, now I learn to look at it this way, since all OBJ-C objects all declared as pointers ` (except for id ), I simply replace the float in C style declaration float myFloat with NSString* myString; I hope this helps clear up some of the Obj-C maze. :)
Replies
In the same way, when you have something like: int *number; Its better look at it like number is of type "int *" which of course means integer pointer. Even though the star is right before the variable name it actually is a "part of the type" if I can put it that way.
Hence for the above reason you see it as: (NSString *)str where the type of the parameter is in the parenthesis and the name is outside.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomeint number
int *number (a integer pointer)
(int *)number ( the same as the above) (i dont know if this is possible)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomeint *number
and
(int *)number
in two very different situations.
When you write int *number you are basically defining a variable that is an integer pointer.
You write (int *)number when you are declaring/defining an Objective C method to specify that your method takes an integer pointer as a parameter
The other situation where you'd see something like (int *)number is when you are doing a C style type cast..which is basically changing the type of a variable (if you don't already know that)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeWhat is confusing is a lot of times we type our declaration like this this: NSString *myString; so makes it look like the"*" is part of myString rather then NSString while it is clearer if you type NSString* myString. this way makes NSString* looks as a whole.
When I first started Obj-C, I was a bit puzzled by this as well, now I learn to look at it this way, since all OBJ-C objects all declared as pointers ` (except for id ), I simply replace the float in C style declaration float myFloat with NSString* myString;
I hope this helps clear up some of the Obj-C maze. :)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome