您的位置:首页 > 其它

extern的使用

2016-07-29 16:14 274 查看
ViewController.h文件

#import <UIKit/UIKit.h>

#define ZiXue @"ABC"

extern BOOL wangWeiChuan_Love;

extern NSString *Tcy;

@interface ViewController :
UIViewController

@end

ViewController.m文件

#import "ViewController.h"

#import "secondeViewController.h"

/*extern使用起来其实非常的简单

 他和#define其实很相似

 就相当于在整个项目中定义了一个全局的变量,在其他的类中如果要使用它直接先调用头文件,然后直接调用它就可以了。

 项目中应该多使用。

 但是能够用宏定义最好还是使用宏定义

 */

@interface
ViewController ()

@end

 BOOL wangWeiChuan_Love;

 NSString *Tcy;

@implementation ViewController

- (void)viewDidLoad {

    [super
viewDidLoad];

    

    wangWeiChuan_Love =
YES;

    

    if (wangWeiChuan_Love ==
NO) {

        Tcy =
@"wangWeiChuan";

    }else{

        Tcy =
@"tangChuanYun";

    }

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent
*)event{

    secondeViewController *seconderVC = [secondeViewController
new];

    

    [self
presentViewController:seconderVC
animated:YES
completion:^{

    }];

}

secondeViewController.m

#import "secondeViewController.h"

#import "ViewController.h"

@interface
secondeViewController ()

@end

@implementation secondeViewController

- (void)viewDidLoad {

    [super
viewDidLoad];

    if (wangWeiChuan_Love ==
YES/*wangWeiChuan_Love*/) {

        self.view.backgroundColor = [UIColor
redColor];

        NSString *string =
Tcy;   

        NSLog(@"%@",string);

    }

    NSLog(@"--->%@",ZiXue);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: