NSMutableData SetLength 错误
我的应用程序从服务器获取一些 json 数据,并使用 NSMUtableData 对象来存储这些数据。 但调试器报告以下错误:
[NSCFString setLength:]: unrecognized selector sent to instance
并且调试器突出显示以下行(在连接 didReceiveResponse 方法中):
[rqst_data setLength:0];
rqst_data 在头文件中声明为 NSMutableData。
提前感谢您的帮助,
斯蒂芬
My app gets some json data from a server and it uses a NSMUtableData object to store these data.
But debugger is reporting the following error:
[NSCFString setLength:]: unrecognized selector sent to instance
and the debugger highlighted the following line (in connection didReceiveResponse method):
[rqst_data setLength:0];
rqst_data is declared as NSMutableData in header file.
Thx in advance for your kind help,
Stephane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您的 rqst_data 变量被释放了。确保您已正确分配它。如果您已为其声明了
@property
,则最好将该变量用作self.rqst_data
。您可以在属性声明中使用
retain
,如果是 IOS 5strong
。您可以通过将 NSZombieEnabled 设置为 YES 来跟踪是否有任何变量被释放。启用僵尸后,发送给已释放对象的消息将不再表现奇怪或以难以理解的方式崩溃,而是会记录消息并以可预测和调试器可断点的方式终止。
您可以通过以下步骤设置
NSZombieEnabled
。从上面的菜单栏中选择产品。按住 alt/option 并选择“测试...”或“运行...”。
1.
转到“参数”选项卡,然后在“环境变量”部分添加
NSZombieEnabled
YES
。或
2。
转到“诊断”选项卡,然后选中“内存管理”部分中的
启用僵尸对象
。It seems your
rqst_data
variable gets released. Make sure you have properly allocated it. If you have declared@property
for it you better use the variable asself.rqst_data
.You can use
retain
and in case of IOS 5strong
in property declaration.You can track if any variable gets released via setting
NSZombieEnabled
toYES
. With zombies enabled, messages to deallocated objects will no longer behave strangely or crash in difficult-to-understand ways, but will instead log a message and die in a predictable and debugger-breakpointable way.You can set
NSZombieEnabled
by the following steps.Select Product from the menu bar above. Keep alt/option pressed and select "Test..." or "Run...".
1.
Go to the Arguments tab, and add
NSZombieEnabled
YES
in the "Environment Variables" section.OR
2.
Go to the Diagnostics tab, and check
Enable Zombie Objects
in the "Memory Management" section.看来您的 rqst_data 指针实际上是指向 NSString 的指针,而不是 NSMutableData 对象。而且你不能设置 NSString 的长度。
也许您没有保留 NSMutableData 对象或过度释放它,以致指向它的指针不再有效。
It appears that your rqst_data pointer is actually pointer to an NSString, not an NSMutableData object. And you can't set the length of a NSString.
Perhaps you have not retained the NSMutableData object or have overreleased it so that the pointer to it is no longer valid.