Swift

blcok

2020-10-16  本文已影响0人  小明讲啥故事
OC
#import "ViewController.h"

@interface ViewController ()

typedef int(^MyFunction) (int a,int b);

@property void (^test001)(NSString*,NSArray*);
@property void (^huuh00)(NSString*,NSArray*);

@property(nonatomic) MyFunction ddd;

@end

@implementation ViewController

- (void)viewDidLoad {
   [super viewDidLoad];
   [self asyncSerial];
    self.test001(@"", [[NSArray alloc] init]);
   self.ddd = ^(int a,int b){
       return 3;
   };
   self.ddd(5,6);
   
   void (^huuh)(void) = ^{
       NSLog(@"逗比");
   };
   huuh();
   
   
   void (^huhusd)(NSString*,NSArray*) = ^(NSString *a,NSArray *b){
       NSLog(@"%@",a);
   };
   
   huhusd(@"s我的s",[NSArray new]);
   
   NSString* (^xian)(void) = ^{
       NSLog(@"逗比");
       return @"ddd";
   };
    
   NSString *a = xian();
}
swift
import UIKit

typealias funcBlock1 = (_ a:String) -> ()
typealias funcBlock2 = (_ a:String) -> (String)

class ViewController: UIViewController {
    var test01:funcBlock1?
    var test02:funcBlock2?
    var test03:((_ a:String) -> ())?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.test01 = { (a) in
            print(a)
        }
        self.test01?("sssss")
        self.test01?("aaaaa")
       
        self.test02 = {(a) -> String in
            return "a"
        }
        self.test02?("bbbbb")
        
        self.test03 = {(a)  in
           print(a)
        }
        self.test03?("ccccc")
        
        let abbbb = {(a:String) -> String in
            return "a"
        }
    }
}

上一篇下一篇

猜你喜欢

热点阅读