NSMutableString 总是“超出范围”?

发布于 2024-10-01 05:37:42 字数 639 浏览 1 评论 0原文

在我的 .h 文件中,我有:

    #import <UIKit/UIKit.h>


@interface untitled : UIViewController 
{
    NSMutableString * sResults;
}

@property (nonatomic,retain) NSMutableString * sResults;

@end

在我的 .mi 有:

#import "untitled.h"


@implementation untitled

@synthesize sResults;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    sResults = [[NSMutableString alloc] initWithString:@"Hello"];
    [sResults appendString:@" World"];
}

@end

每当我检查 sResults 时,它都会说“超出范围”..我做错了什么?

in my .h file i have:

    #import <UIKit/UIKit.h>


@interface untitled : UIViewController 
{
    NSMutableString * sResults;
}

@property (nonatomic,retain) NSMutableString * sResults;

@end

In my .m i have:

#import "untitled.h"


@implementation untitled

@synthesize sResults;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    sResults = [[NSMutableString alloc] initWithString:@"Hello"];
    [sResults appendString:@" World"];
}

@end

Whenever i check sResults it says "Out of scope".. what am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

会发光的星星闪亮亮i 2024-10-08 05:37:42

试试这个:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sResults = [NSMutableString stringWithString:@"Hello"]; //retained in synthesized setter
    [self.sResults appendString:@" World"];
}

Try this:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sResults = [NSMutableString stringWithString:@"Hello"]; //retained in synthesized setter
    [self.sResults appendString:@" World"];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文