Cocoa - Strings as arguments
I need to pass a string as an argument but I dont know how..Help?
-(void)sendSMS: (int) number:(NSString)carrier;
That says objects cant be used as p开发者_如何学Goarameters.
You should be using NSString* (notice the *) - what you want to be passing around is a pointer to an NSString object.
Try this (this naming convention is also much more Objective-c like):
-(void)sendSMStoNumber:(int)number withCarrier:(NSString*)carrier;
[myObject sendSMStoNumber:3 withCarrier:@"AT&T"];
Side Note, I'd recommend having your number variable be an NSString* as well, 10 digit numbers being what you're probably passing for a phone number and all, but I really don't know anything about what you're implementing and how.
You were missing the pointer * in there:
-(void)sendSMS: (int) number:(NSString *)carrier;
That method is screwed up in a few ways. First, you can't pass a plain NSString — objects are always referenced through pointers. You also don't have a name for the first parameter, and the carrier
argument is labeled as number:
. I think you probably meant something like - (void)sendSMS:(NSInteger)number carrier:(NSString *)carrier
.
(But even that is not really ideal if the number
argument is supposed to represent a phone number. Phone numbers can start with a zero, while integers cannot.)
精彩评论