使用 NSString 类型的表达式初始化 NSMutableString 的指针不兼容 - 警告
大家好,我收到了这段代码,并收到警告“使用 NSString 类型的表达式初始化 NSMutableString 的指针不兼容”和内存泄漏。有人似乎知道如何纠正这个问题吗?
- (IBAction)numberClicked:(id)sender {
UIButton * numberBtn = (UIButton*)sender;
NSMutableString *value = (self.textField.text == nil ? [NSMutableString new] : self.textField.text );
[value appendString:[NSString stringWithFormat:@"%d",numberBtn.tag]];
self.textField.text = value;
}
thnaks
Hi guys i got this piece of code and got a warning "Incompatible pointer initializing NSMutableString with an expression of type NSString" and a mem leak. does anyone seem to know how to correct this?
- (IBAction)numberClicked:(id)sender {
UIButton * numberBtn = (UIButton*)sender;
NSMutableString *value = (self.textField.text == nil ? [NSMutableString new] : self.textField.text );
[value appendString:[NSString stringWithFormat:@"%d",numberBtn.tag]];
self.textField.text = value;
}
thnaks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要消除不兼容的指针警告,您需要将
self.textField.text
的可变副本分配给value
:To get rid of the incompatible pointer warning, you need to assign a mutable copy of
self.textField.text
tovalue
: