class对象的Objective-C @property变量

时间:2021-07-17 20:00:01

In my code i declare an @property for my Main class in my sub class to set values there

在我的代码中,我为我的子类声明一个@property来设置那里的值

@property(nonatomic,retain)  MainViewController *father;

but i noticed that retain make the dealloc method not called in my main class, but when i change it to:

但是我注意到retain make dealloc方法在我的主类中没有调用,但是当我将它改为:

@property(strong, nonatomic)  BabyViewController *father;

the dealloc method returned to be called.

返回dealloc方法以进行调用。

i did this without knowing if that effect my code performance or not.

我这样做时并不知道这是否会影响我的代码性能。

i used this property to do this in my main class:

我在主课程中使用了这个属性:

    subClass* controller = [[subClass alloc] initWithPageNumber:page];
    controller.father=self;
    [controller.view removeFromSuperview];

is this the best i can do ??

这是我能做的最好的吗?

1 个解决方案

#1


3  

Better you can use assign property for the declaration of viewControllers and delegates.It will assign the data and won't dealloc the variable. So use like this,

更好的方法是为viewControllers和delegate的声明使用assign属性。它将分配数据,而不会释放变量。所以用这样的,

@property(nonatomic,assign)  MainViewController *father;

#1


3  

Better you can use assign property for the declaration of viewControllers and delegates.It will assign the data and won't dealloc the variable. So use like this,

更好的方法是为viewControllers和delegate的声明使用assign属性。它将分配数据,而不会释放变量。所以用这样的,

@property(nonatomic,assign)  MainViewController *father;