Declaring a method with +
means that it is a class method. Within a class method self
refers to the class itself, which in your case would be [WebService class]
. If you declared and instance method (using -
) then inside the method self
would refer to the instance, which is what you want.
To set an instance variable - you need an instance
WebService *webService = [[WebService alloc] init];
webService.myString = @"some string";
Now to make your method work you need to declare it with a -
instead of +
which makes it an instance method
- (void)printMyString:(NSString *)someString
{
[self setMyString:someString];
NSLog(@"myString is set to %@",self.myString);
}
Now
[webService printMyString:@"boom"];
results in the instance variable myString
being set to boom
and the console logging out `myString is set to boom".