[iPhone]全局变量 [英] [iPhone] Global Variables

查看:96
本文介绍了[iPhone]全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有谁能告诉我如何定义可以在整个应用程序中开始使用的全局变量?

目前,我已经尝试过,但是,它显然给我抛出了错误.. ::

http://plaatscode.be/141545/
http://plaatscode.be/141543/

第二个网址的第7、8、9行出现错误:
-从不兼容的类型"id"分配给"NSString"
-从不兼容的类型"id"分配给"NSString"
-从不兼容的类型数据库* __ strong"分配给数据库"

另一种选择是将这些值直接传递给状态机.


Hi everyone,

Is there anyone who could tell me how i could define global variables which I could start using in my entire application?

currently I''ve tried, However, it is throwing me errors obviously..:

http://plaatscode.be/141545/
http://plaatscode.be/141543/

errors on lines 7,8,9 of the second url:
- Assigning to ''NSString'' from incompatible type ''id''
- Assigning to ''NSString'' from incompatible type ''id''
- Assigning to ''Database'' from incompatible type ''Database *__strong''

An alternative would be to pass these values directly to the statemachine.


LoginStateMachine *machine = [[LoginStateMachine alloc] init];
[machine Login];





有谁可以帮助我定义全局变量吗?

亲切的问候,
Lars





Anyone who could help me with defining global variables?

Kind Regards,
Lars

推荐答案

想到的第一个想法是单例,令人惊讶的是它也是首选方法.请查看此链接以获取更多信息:
http://derekneely.com/2009/11/iphone-development-global-variables/ [ ^ ]

祝你好运!
The first idea that came into mind was a singleton, and surprisingly it is also the preferred method. Check out this link for more info:
http://derekneely.com/2009/11/iphone-development-global-variables/[^]

Good luck!


这篇关于[iPhone]全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆