我们过go 常常声明property
以在类之间传递数据,如下所示:
.h file (interface file)
@property (nonatomic) double topSpeed;
.m file (implementation file)
@synthesize topSpeed;
现在没有interface
个类,如何在.swift
个类之间传递数据?
我们过go 常常声明property
以在类之间传递数据,如下所示:
.h file (interface file)
@property (nonatomic) double topSpeed;
.m file (implementation file)
@synthesize topSpeed;
现在没有interface
个类,如何在.swift
个类之间传递数据?
Swift不区分属性和实例变量(即属性的底层存储).要定义属性,只需在类的上下文中声明一个变量.
swift类只是一个类名.swift文件.
将类和属性声明为
class SomeClass {
var topSpeed: Double
var aStrProperty: String
var anIntProperty: Int
//Initializers and other functions
}
可以通过点符号访问属性值.从Xcode6 beta 4开始,Swift中还有访问修饰符(public
、internal
和private
).默认情况下,每个属性都是internal
.See here了解更多信息.
有关更多信息,请参阅Swift Programming Guide:
存储的属性和实例变量
如果你有Objective-C的经验,你可能知道它提供了
Swift将这些概念统一到一个属性声明中.A.