【发布时间】:2012-07-04 07:56:23
【问题描述】:
在使用 C++ 之后,我是 Objective-C 的新手。 在 XML 文件解析期间使用 NSMutableString 时遇到问题。 我有这样的 NSMutableString 结构:
struct HotelStruct {
...
NSMutableString *h_name;
...
};
然后,我将 CurrentStruct 声明为 ParserDelegate 的实例变量:
@interface ParserDelegate : NSObject <NSXMLParserDelegate> {
...
struct HotelStruct CurrentStruct;
...
}
最后,我尝试将字符串附加到 CurrentStruct.h_name (m_isName == YES):
-(void)parser:(NSXMLParser*)parser foundCharacters:(NSString *)string {
if (m_isName) {
[CurrentStruct.h_name appendString:string];
}
但是调试器说 CurrentStruct.h_name 在像之前一样执行 AppendString 之后仍然是 0x0,而字符串变量具有所需的值。 我有点困惑,因为看起来 appendString 只是被跳过了。 我会很感激任何帮助。谢谢!
【问题讨论】:
-
向 nil 发送消息总是会导致 ObjC 中的空操作。如果您知道 CurrentStruct.h_name == 0x0、appendString: 或您发送的任何其他消息,它不会有任何区别。把它想象成乘以 0
-
哦,这确实解释了一些事情。看起来 CurrentStruct.h_name 在某处变为 nil 。我正在完成另一个人的项目,所以我想他的代码中可能会有答案。非常感谢,非常感谢您的帮助!
标签: objective-c ios