Reputation: 71
system1I want to verify this syntax ( when pressing a radio group). Is this syntax correct :
if([[sender selectedCell ] tag]==1)
[prefs addChild:element(@"System", [NSString stringWithUTF8String:"system1"])];
if([[sender selectedCell] tag]==2)
[prefs addChild:element(@"system", [NSString stringWithUTF8String:"system2"])];
if([[sender selectedCell] tag]==3) {
[advancedButton setEnabled:NO];
[notifs addChild:element(@"UploadedFiles", [NSString stringWithUTF8String:"YES"])];
[notifs addChild:element(@"DeletedFiles", [NSString stringWithUTF8String:"YES"])];
}
Upvotes: 0
Views: 54
Reputation: 35646
Yes that would be correct. tag
property is just an NSInteger
so you can compare it to 1.
Upvotes: 3
Reputation: 14068
if([[sender selectedCell] tag]==1) {/* do something */}
:)
Despite of that it should be fine.
The devil is in the details here. sender ist just an id object and therefore not more than NSObject *. You cannot just access the method without typecasting or receiving a compiler warning. It may not even compile when you use ARC.
For a full picture:
(IBAction) performMyAction:(id) sender {
if ([sender isKindOfClass:[MyVeryOwnClass class]]) {
MyVeryOwnClass myVeryOwnObject = (MyVeryOwnClass *) sender;
if([[myVeryOwnObject selectedCell] tag]==1) {
/* here goes the business logic */
}
}
}
There are other ways of archieving the same. You can just typecast stender without assigning it to a temp object reference. Or you can use performsToSelector: and performSelector to access selectedCell. For some reason I prefer it this way. I feel this is well readable and debugging is easy.
Upvotes: 1