【问题标题】:Objective-C instance variable vs @interface variable [duplicate]Objective-C实例变量与@interface变量[重复]
【发布时间】:2014-09-16 06:55:54
【问题描述】:

我是 iOS 编程新手,很难理解实例变量的区别。我给你发了两个例子,你能解释一下有什么区别吗? (仅适用于不是 IBOutlet 的实例变量)。

在 .m 文件中

@interface MyClass ()
  @property(nonatomic, strong) NSString *aString;
@end

在 .m 文件中

@implementation MyClass
{
   NSString *_aString;
}

在这两种情况下,我都在 .m 文件中,并且我正在声明“实例”变量。但是,在@interface(.m 文件)中声明它们和在 @implementation 中使用 {} 声明它们有什么区别?

我已经排除了 IBOutlet,因为只有 @interface 有(我猜...)

【问题讨论】:

    标签: objective-c


    【解决方案1】:

    @interface 变量称为property - 因此称为@property

    查看此来源以找出差异:

    Difference between properties and variables

    【讨论】:

      猜你喜欢
      • 2013-08-18
      • 2013-02-02
      • 2023-04-04
      • 2011-05-07
      • 2011-10-26
      • 1970-01-01
      • 2012-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多