问题1:block用多了好不好,感觉很高大尚一样。
问题2:里面很多申明使用extern,如申明block.这样一搞。全项目都可以用了。。如果这样,oc类方法都不用了,直接的用extern不久好了?
我自己简单的写了一个demo。如下:
#import "ViewController.h"
#import "TwoVC.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
for (id obj in blockData(@"name", 32)){
NSLog(@"obj = %@",obj);
}
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 100, 100);
[btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark- 申明
extern NSArray *blockData(NSString * string , NSUInteger age);
NSArray *blockData(NSString * string , NSUInteger age) {
NSArray *arr = @[string,@(age)];
return arr;
};
- (void)btnAction
{
TwoVC *tvc = [[TwoVC alloc] init];
[self presentViewController:tvc animated:YES completion:nil];
}
==================================================
#import "TwoVC.h"
@interface TwoVC ()
@end
@implementation TwoVC
- (void)viewDidLoad {
[super viewDidLoad];
for (id obj in blockData(@"name1", 322)){
NSLog(@"obj = %@",obj);
}
// Do any additional setup after loading the view.
}
extern NSArray *blockData(NSString * string , NSUInteger age);
多给点看法,没关系,只是作为一个讨论。
问题2:里面很多申明使用extern,如申明block.这样一搞。全项目都可以用了。。如果这样,oc类方法都不用了,直接的用extern不久好了?
我自己简单的写了一个demo。如下:
#import "ViewController.h"
#import "TwoVC.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
for (id obj in blockData(@"name", 32)){
NSLog(@"obj = %@",obj);
}
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 100, 100);
[btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark- 申明
extern NSArray *blockData(NSString * string , NSUInteger age);
NSArray *blockData(NSString * string , NSUInteger age) {
NSArray *arr = @[string,@(age)];
return arr;
};
- (void)btnAction
{
TwoVC *tvc = [[TwoVC alloc] init];
[self presentViewController:tvc animated:YES completion:nil];
}
==================================================
#import "TwoVC.h"
@interface TwoVC ()
@end
@implementation TwoVC
- (void)viewDidLoad {
[super viewDidLoad];
for (id obj in blockData(@"name1", 322)){
NSLog(@"obj = %@",obj);
}
// Do any additional setup after loading the view.
}
extern NSArray *blockData(NSString * string , NSUInteger age);
多给点看法,没关系,只是作为一个讨论。