IOS中设置全局变量
2015-11-02 17:56
399 查看
有几种方法
some developers recommend use singleton patter (ref link http://blog.csdn.net/kmyhy/article/details/7026511)
方法1:使用静态变量 (不推荐)
方法2: 使用singleton pattern (ref link: http://nice.iteye.com/blog/855839)
方法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: http://nice.iteye.com/blog/855839)
方法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;
相关文章推荐
- 神器SystemTap
- Python 七步捉虫法
- Lua编程示例(一):select、debug、可变参数、table操作、error
- C#中的两种debug方法介绍
- 用Ruby实现一个单元测试框架的教程
- js调试工具 Javascript Debug Toolkit 2.0.0版本发布
- php debug 安装技巧
- iOS开发之路--微博“更多”页面
- Lua中的异常处理pcall、xpcall、debug使用实例
- 在Python编程过程中用单元测试法调试代码的介绍
- iOS开发之路--微博骨架搭建
- IOS开发代码分享之获取启动画面图片的string
- Android APK使用Debug签名重新打包 Eclipse更改默认Debug签名
- IOS开发之路--C语言数组和字符串
- IOS开发代码分享之用nstimer实现倒计时功能
- IOS开发代码分享之设置UISearchBar的背景颜色
- Node.js 学习笔记之一
- Openstack Murano(Kilo) 网络排错
- 如何利用Object Browser图形化工具提高Oracle开发工作效率(二)对象创建管理篇
- 在Eclipse里调试Vert.X