我知道如果我使用
@interface TPN : UIViewController{
IBOutlet UIView *testView;
}
@property (strong, nonatomic) IBOutlet UIView *testView;
我知道第一个本质上是一个私有(private)变量,只能在类内访问。第二个“@property”可以从实例化对象访问。我发现在大多数教程中,当人们通常从类本身更改 socket 时,他们往往会设置属性,这很奇怪。有什么我应该遵循的准则吗?
最佳答案
您根本不再需要指定 ivar。也不需要使用@synthesize。
使用属性,但要确保它是弱的,而不是强的
@interface TPN : UIViewController
@property (weak, nonatomic) IBOutlet UIView *testView;
在实现中,您现在可以将 ivar 作为 _testView 访问。
对于私有(private)属性(以上是公共(public)属性),而不是将@property 放在实现文件的类别中:
#import "TPN.h"
@interface TPN ()
@property (weak, nonatomic) IBOutlet UIView *testView;
@end
@implementation TPN
....
关于iOS SDK - 与 socket 建立连接的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17580752/