mainController = (ViewController *)self.presentingViewController;
mainController.pressureUnit = _pressureSettings.selectedSegmentIndex;
我会用Objective C来实现这个,那么在Swift中该怎么做呢?
mainController = (ViewController *)self.presentingViewController;
mainController.pressureUnit = _pressureSettings.selectedSegmentIndex;
我会用Objective C来实现这个,那么在Swift中该怎么做呢?
otherClass().methodFromOtherClass() 是 Swift 的语法。
如果你必须传递一个带有外部名称的属性,可以使用以下方法:
otherClass().methodFromOtherClass(propertyName: stringName) // 传递字符串的示例
如果要调用返回方法结果的方法执行某些操作:
let returnValue = otherClass().methodFromOtherClass(propertyName: stringName)
访问属性或函数的示例
class CarFactory {
var name = ""
var color = ""
var horsepower = 0
var automaticOption = false
func description() {
println("My \(name) is \(color) and has \(horsepower) horsepowers")
}
}
var myCar = CarFactory()
myFirstCar.name = "Mustang"
myCar.color = "Red"
myCar.horsepower = 200 myCar.automaticOption = true
myFirstCar.description() // $: "My Mustang is Red and has 200 horsepowers and is Automatic"
摘自: Apple Inc. “The Swift Programming Language.” iBooks.
在这里你只调用了该方法,而不是类的新实例。
class SomeClass {
class func someTypeMethod() {
// type method implementation goes here
}
}
SomeClass.someTypeMethod()