Block C->A

2017-11-07  本文已影响0人  yuezishenyou

界面传值

单利 .h

typedef void (^callBlock)(NSString *str);

@interface Global : NSObject

@property (nonatomic, copy) callBlock callblock;

+ (instancetype)manager;

- (void)readBlock:(callBlock)block;
- (void)setBlock:(NSString *)str;

@end

.m

@implementation Global

+ (instancetype)manager
{
    static Global *_manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (_manager == nil) {
            _manager = [[Global alloc]init];
        }
    });
    return _manager;
}

- (void)readBlock:(callBlock)block{
    _callblock = [block copy];
}
- (void)setBlock:(NSString *)str{
    if (_callblock) {
        _callblock(str);
    }
}

@end
上一篇下一篇

猜你喜欢

热点阅读