iOS: 设置全局变量
2012-03-14 23:41
525 查看
有几种方法
some developers recommend use singleton patter (ref link http://blog.csdn.net/kmyhy/article/details/7026511)
方法1:使用静态变量 (不推荐)
方法2: 使用singleton pattern (ref link: /article/7463156.html)
方法3:把全局变量设置到AppDelegate中
例: 定义和使用一个全局变量"isLogin"
AppDelegate.h
@interface AppDelegate :UIResponder <UIApplicationDelegate>
@property (strong,nonatomic)UIWindow
*window;
@propertyBOOL isLogin;
@end
AppDelegate.m
@implementation AppDelegate
@synthesize window =_window;
@synthesize isLogin;
@end
那么在其他的class里,则可以通过下列代码调用全局变量
AppDelegate *delegate=(AppDelegate*)[[UIApplicationsharedApplication]delegate];
delegate.isLogin=YES;
some developers recommend use singleton patter (ref link http://blog.csdn.net/kmyhy/article/details/7026511)
方法1:使用静态变量 (不推荐)
方法2: 使用singleton pattern (ref link: /article/7463156.html)
方法3:把全局变量设置到AppDelegate中
例: 定义和使用一个全局变量"isLogin"
AppDelegate.h
@interface AppDelegate :UIResponder <UIApplicationDelegate>
@property (strong,nonatomic)UIWindow
*window;
@propertyBOOL isLogin;
@end
AppDelegate.m
@implementation AppDelegate
@synthesize window =_window;
@synthesize isLogin;
@end
那么在其他的class里,则可以通过下列代码调用全局变量
AppDelegate *delegate=(AppDelegate*)[[UIApplicationsharedApplication]delegate];
delegate.isLogin=YES;
相关文章推荐
- ios开发之 全局变量设置
- IOS中设置全局变量
- iOS: 设置全局变量
- iOS全局变量设置
- ios AppDelegate设置全局变量
- ios中在AppDelegate设置全局变量
- ios app应用中在AppDelegate设置全局变量
- IOS 设置全局变量
- IOS中设置全局变量
- iOS 通过AppDelegate设置全局变量【原创】
- ios设置全局变量
- IOS中设置全局变量
- ios开发中全局变量设置和调用方法
- IOS中设置全局变量
- jmeter如何设置全局变量以及调用方法
- Habber - IOS XMPP 客户端 教程 (二)应用XMPP&代理&全局变量
- IOS 成员变量,属性变量,局部变量,实例变量,全局变量 详解
- iOS中全局变量的几种使用方法
- 跟我学AngularJS:全局变量设置之value vs constant vs rootscope vs 服务[转]
- 设置 UINavigationBar 全局颜色,背景颜色,前景颜色 swift 3 4 ios 10 +