在我的应用程序中,我创建了我的自定义类,我正在使用KVO观察其属性之一,因此如果其值发生更改,它会立即显示在firstview控制器对象(标签或...)中
示例代码
myCustomClass.h
@interface myCustomClass : NSObject {
NSString * text;
}
@property (nonatomic, retain) NSString * text;
- (void)changetext;
Run Code Online (Sandbox Code Playgroud)
myCustomClass.m
@implementation myCustomClass
@synthesize text;
static myCustomClass * _sharedInstance;
- (id)init
{
if ((self = [super init])) {
text = @ "";
}
return self;
}
+ (myCustomClass *)sharedInstance
{
if (!_sharedInstance) {
_sharedInstance = [[myCustomClass alloc] init];
}
return _sharedInstance;
}
- (void)changetext {
text = @ "changed";
}
Run Code Online (Sandbox Code Playgroud)
firstViewController.h
@interface FirstViewController:UIViewController {
IBOutlet UILabel * label;
}
@property …Run Code Online (Sandbox Code Playgroud)