开发者

Proper way to declare two parameters in a Objective-C method?

开发者 https://www.devze.com 2023-02-14 13:20 出处:网络
This might be a ridiculous question but I can\'t find it asked yet here already. Have a protocol delegate method defined:

This might be a ridiculous question but I can't find it asked yet here already.

Have a protocol delegate method defined:

- (void)myAddViewController:(MyAddViewController *)myAddViewController 
             loadGPS:(BOOL)gps loadCamera:(BOOL)camera;

which basically is to determine whether the GPS system is to be loaded or the camera should be loaded.

I call this method via:

[self.delegate myAddViewController:self loadGPS:YES loadCamera:NO];
// or alternatively
[self.delegate myAddViewController:self loadGPS:NO loadCamera:YES];

Inside my implemented method in the delegate we have:

- (void)myAddViewController:(MyAddViewController *)myAddViewController loadGPS:(BOOL)gps loadCamera:(BOOL)camera {
 .... .... ...  
if (gps) {
        ......
    }

    if (camera) {
      // camera is ALWAYS nil and never seems to be set?!
      .....

    }

So why when I call the delegate method with Camera: YES is the camera var always nil? It seems like it is never recognizing my second var yet it doesn't mind comp开发者_如何学Ciling? :)


It seems like a waste to pass in two mutually exclusive boolean values to a method.

Perhaps you'd be better with two delegate methods:

[self.delegate myAddGPSViewController:self];
// or alternatively
[self.delegate myAddCameraViewController:self];

because when you're firing the delegate methods, you'll already know whether you want GPS or Camera anyway.


It might have, declaring 'camera' variable again, can you paste your method

- (void)myAddViewController:(MyAddViewController *)myAddViewController loadGPS:(BOOL)gps loadCamera:(BOOL)camera {

\here?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号