NSString“无效摘要”
好吧,我已经阅读了很多有关此问题的帖子和资源,但我仍然遇到同样的问题。我有一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用下面的内容
了解更多信息,请阅读 SO 帖子
NSString 分配中的无效摘要
use below
for more read the SO post
Invalid Summary in NSString assignment
你能把类代码放在这里吗?您处理 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.
我能够通过将 NSMutableString 初始化为大小 100 并仅附加到它来重现无效摘要。 打电话时,我发现问题消失了
当我之前
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
prior to