OC:MZSafeCallBack
2019-04-30 本文已影响0人
春暖花已开
说明 | 时间 |
---|---|
首次发布 | 2019年04月30日 |
最近更新 | 2019年05月26日 |
DetailViewController
// DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property (nonatomic, copy) void (^passValueBlock)(NSString *text, BOOL isTrue, NSString * _Nullable type);
@end
// DetailViewController.m
#import "DetailViewController.h"
#define MZSafeCallBack(aBlock, ...) do {!aBlock ?: aBlock(__VA_ARGS__);} while(0)
@interface DetailViewController ()
@end
@implementation DetailViewController
- (IBAction)onBackPage:(id)sender {
MZSafeCallBack(self.passValueBlock, @"success", YES, nil);
[self.navigationController popViewControllerAnimated:YES];
}
@end
HomeViewController
#import "HomeViewController.h"
#import "DetailViewController.h"
@interface HomeViewController ()
@end
@implementation HomeViewController
- (IBAction)onNextPage:(id)sender {
DetailViewController *detailVC = [[DetailViewController alloc] init];
detailVC.passValueBlock = ^(NSString * _Nonnull text, BOOL isTrue, NSString * _Nullable type) {
NSLog(@"text = %@, isTrue = %d, type = %@", text, isTrue, type);
};
[self.navigationController pushViewController:detailVC animated:YES];
}
@end
拓展
null
打印出是尖括号<null>
,nil
是圆括号(null)
NSLog(@"%@--%@", [NSNull null], nil);
打印出:<null>--(null)