objective-c - using a boolean value from one class

2019-06-14 18:57发布

I've looked around and couldn't find a distinct answer to this question. So I'm asking here. I have two classes. ClassA and ClassB. I have a bool value in ClassB. I have a method in ClassA where it is looking for that value in ClassB to be True in order for the method to fire off. I'm not really sure how to get ClassA to see that value. Any help would be great. Thanks in advance!

1条回答
不美不萌又怎样
2楼-- · 2019-06-14 19:13

be careful with the "global definition". if your class must save the user settings, you can use: for save:

 NSUserDefaults *pref = [NSUserDefaults standardUserDefaults];
 [pref setBool:YES forKey:@"AudioIsON"];
 [pref synchronize];

for reading:

BOOL myBooleanSetting = [[NSUserDefaults standardUserDefaults] boolForKey:@"AudioIsON"];

instead of, is better to learn the delegate and the property.

hope this help you.

查看更多
登录 后发表回答