NSString“无效摘要”

发布于 2024-11-18 09:11:13 字数 831 浏览 2 评论 0原文

好吧,我已经阅读了很多有关此问题的帖子和资源,但我仍然遇到同样的问题。我有一些 NSString 变量,我需要将它们作为类范围的变量在整个类的多个位置使用。我尝试了很多设置组合。首先,我确实在接口中声明了字符串,如下所示:

@interface iCodeViewController : UIViewController <NSXMLParserDelegate> {

    NSString *myString;
}

我还添加了如下属性(我尝试过使用和不使用属性并进行合成)

@property (readwrite, retain) NSString *myString;

我也尝试过,(非原子,保留),(非原子,复制),(读写,复制)。

然后在 .m 文件中:

@synthesize myString;

我已经尝试过:

self.myString = @"whatever";
myString = @"whatever";

我也尝试过通过以下方式分配内存和不分配内存:

myString = [[NSString alloc] init];

我错过了什么?

在我“应该”在一种方法中设置字符串变量后,我尝试使用 if ([myString isEqualToString:@"blah blah"]) 在另一种方法中检查它,当我放入断点并将鼠标悬停在 myString 上,它始终显示“无效摘要”。

谢谢!

Ok, I have read a lot of posts and resources about this but I am STILL having the same issue. I have a few NSString variables that I need to be class-wide variables used in multiple places throughout the class. I have tried many combinations of settings. First of all, I do have the strings declared in the interface like so:

@interface iCodeViewController : UIViewController <NSXMLParserDelegate> {

    NSString *myString;
}

I have also added the property as follows (I have tried with and without the property and synthesizing)

@property (readwrite, retain) NSString *myString;

I have also tried, (nonatomic, retain), (nonatomic, copy), (readwrite, copy).

Then in the .m file:

@synthesize myString;

I have tried:

self.myString = @"whatever";
myString = @"whatever";

I have also tried with and without allocating memory to it by:

myString = [[NSString alloc] init];

What am I missing??

After I have 'supposedly' set the string variable in one method, I try to check it in another with if ([myString isEqualToString:@"blah blah"]) and when I put in a breakpoint and hover over myString it is always showing 'invalid summary.

Thanks!

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

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

发布评论

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

评论(3

一枫情书 2024-11-25 09:11:13

使用下面的内容

@property (nonatomic, retain) NSString *myString;
self.myString = [NSString  stringWithString:@"whatever"];

了解更多信息,请阅读 SO 帖子

NSString 分配中的无效摘要

use below

@property (nonatomic, retain) NSString *myString;
self.myString = [NSString  stringWithString:@"whatever"];

for more read the SO post

Invalid Summary in NSString assignment

甜嗑 2024-11-25 09:11:13

你能把类代码放在这里吗?您处理 myString 的方式非常好。
我能想到的一种可能性是您忘记从 init 方法返回 self 。

您的代码中的某些位置可能存在其他可能与内存相关的混乱。

Can you place the class code here? The way you are handling your myString is perfectly fine.
One possibility I can think of is that you are forgetting to return self from the init method.

There could be other possible memory related mess some where in your code.

浅笑轻吟梦一曲 2024-11-25 09:11:13

我能够通过将 NSMutableString 初始化为大小 100 并仅附加到它来重现无效摘要。 打电话时,我发现问题消失了

[mutableString setString:@""];

当我之前

[mutableString appendString:string]; 

I was able to reproduce the invalid summary by initializing an NSMutableString to size 100 and only appending to it. I found the problem went away when I called

[mutableString setString:@""];

prior to

[mutableString appendString:string]; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文