mainController = (ViewController *)self.presentingViewController;
mainController.pressureUnit = _pressureSettings.selectedSegmentIndex;
This is how I will do it in Objective C. How do I do this in swift?
otherClass().methodFromOtherClass() is the syntax for swift
If you have to pass a property with an external name it might be:
otherClass().methodFromOtherClass(propertyName: stringName) //example of passing a string
To call the method to do something, if it is returning a result of a method:
let returnValue = otherClass().methodFromOtherClass(propertyName: stringName)
Example of accessing a property or a function
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"
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.
Here you just call the method but not a new instance of the class.
class SomeClass {
class func someTypeMethod() {
// type method implementation goes here
}
}
SomeClass.someTypeMethod()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With