ARC抱怨实例变量 [英] ARC complaining about instance vairiables

查看:75
本文介绍了ARC抱怨实例变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将非ARC项目转换为使用ARC,但由于某种原因,它抱怨 使用所有实例变量.

I am trying to convert non-ARC project to use ARC but for some reason its complaining about the use of all instance variables.

@property (nonatomic,retain)id myvariable;

产生

Error : "Use of undeclared variable _myvariable"

我的代码中有些地方我不想修改保留计数,但要对该属性进行赋值.所以我使用一个实例变量.

there are some places in my code where I don't want to modify retain count but do an assignment to the property. so I use an instance variable.

添加@syhtnesize myvariable =_myvariable可解决此问题,但我试图找出解决此问题的正确方法.

adding @syhtnesize myvariable =_myvariable resolves this problem but I am trying to figure out the right way to fix this.

可能的解决方案:

1)添加synthesize

2)将实例变量的使用替换为self.myvariable,并分配属性.

2) replace use of instance variable with self.myvariable and make property assigned.

问题扩展 ARC错误

推荐答案

这听起来像是您实现了向后兼容性功能.

It sounds like you've hit a backward compatibility feature.

由于Xcode 4.4属性声明不再需要@synthesize语句,并且没有该声明,编译器会自动生成_propertyName实例变量.

Since Xcode 4.4 property declarations no longer require an @synthesize statement and without one the compiler auto-generates an _propertyName instance variable.

但是对于@synthesize propertyName,就像您在Xcode 4.4之前一样,编译器将自动生成propertyName-不带下划线-实例变量.

However with an @synthesize propertyName, as you would pre-Xcode 4.4, then the compiler will auto-generate an propertyName - note no underscore - instance variable.

警告您使用未声明的变量_myvariable"的编译器消息建议您已将代码切换为使用下划线,但仍有一些@synthesize myvariable语句.

The compiler messages warning you "Use of undeclared variable _myvariable" suggest you have switched the code to use underscores but still have some @synthesize myvariable statements.

您使用@synthesize myvariable = _myvariable直接指定用于实例变量的名称,因此可以解决您的问题,但是通常删除@synthesize是常见的方法.

Your use of @synthesize myvariable = _myvariable specifies the name to use for the instance variable directly, and so solves your problem, but removing the @synthesize completely is the usual approach.

这篇关于ARC抱怨实例变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆