美文网首页
OC:MZSafeCallBack

OC:MZSafeCallBack

作者: 春暖花已开 | 来源:发表于2019-04-30 09:53 被阅读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)
    

    相关文章

      网友评论

          本文标题:OC:MZSafeCallBack

          本文链接:https://www.haomeiwen.com/subject/knkmnqtx.html