Objective-C:如何作为全局访问字符串变量? [英] Objective-C: How Can I Access String Variable As a Global?

查看:121
本文介绍了Objective-C:如何作为全局访问字符串变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发的新手。我想在所有类方法中访问一个字符串变量,我想全局访问该字符串。我怎么能这样做?

I am new to iPhone development. I want to access a string variable in all the class methods, and I want to access that string globally. How can I do this?

请帮帮我。

推荐答案

您可以通过在委托类中实现getter和setter来实现这一点。

You can achieve that by implementing getter and setters in the delegate class.

在委托.h文件中

包括UIApplication委托

Include UIApplication delegate

 @interface DevAppDelegate : NSObject <UIApplicationDelegate>

  NSString * currentTitle;

 - (void) setCurrentTitle:(NSString *) currentTitle;
 - (NSString *) getCurrentTitle; 

在Delegate实现类中.m

In Delegate implementation class .m

 -(void) setCurrentLink:(NSString *) storydata{
currentLink = storydata;

}

-(NSString *) getCurrentLink{
if ( currentLink == nil ) {
    currentLink = @"Display StoryLink";
}
return currentLink;
}

因此,您要评估的变量是通过setters方法在currentlink字符串中设置的你想要字符串的类,只需使用getter方法。

So the variable you to assess is set in the currentlink string by setters method and class where you want the string ,just use the getter method.

所有最好的

这篇关于Objective-C:如何作为全局访问字符串变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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