Really new with objective c (building iphone app) and I’m trying to figure out how to properly understand how calling methods work (compared to c#, the most recent language I’ve been working with)
I have this implementation
@interface User : NSObject{
}
@property NSInteger Id;
@property NSString *email, *password;
-(BOOL)isValid;
@end
@implementation User
-(BOOL)isValid{
NSString *password = self.validateString:self.password;
NSString *email = self.email;
if(validUser){
return YES;
}else{
return NO;
}
}
EDIT: SOrry if it wasn’t clear but this is the method I’m trying to call.
-(NSString *)validateString:(NSString *)string{
// process the string
return @"";
}
Basically I’m trying to create an instance in my view onclick of a button like so:
- (IBAction)btnSubmit:(id)sender {
// get values of email and password
// do an isvalid to check with web service.
User *user = [[User alloc] init];
user.email = @"email@email.com";
user.rawPassword = @"pass";
if(user.isValid){
// go to next page
}
else{
// else refresh current page
}
}
Is creating the instance on click and then passwing the values to process inside the instance a good practice?
Thanks!
No need of creating it’s own object there. You can use the current object for doing this:
You can refer to same object within its scope using
selfkeyword. It’s similar tothiskeyword used in C++