So I have a class of which I want to create an instance as soon as the app launches. I would like to initialize some of its properties from switches/toggles in my ViewController.
Here is the class, of which I am trying to create an instance:
import Foundation
class PropertyCollection {
var property1: Bool
init (property1: Bool) {
self.property1 = property1
}
func disableAll() {
self.property1 = false
}
func enableAll() {
self.property1 = true
}
func info() -> String {
return "The properties are: \(property1)"
}
}
So:
Putting the declaration in AppDelegate.swift
gives me an error ("Use of unresoved identifier 'property1Switch'"):
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
var thePropertyCollection: PropertyCollection = PropertyCollection(property1: property1Switch.isOn)
return true
}
Adding "ViewController." in front of "property1switch" doesn't help either. I get another error ("Instance Member 'property1Switch' cannot be used on type 'ViewController'")
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
var thePropertyCollection: PropertyCollection = PropertyCollection(property1: ViewController.property1Switch.isOn)
return true
}
But I am not trying to "use type 'property1Switch' on type 'View Controller'". I thought this was how you reference stuff from other classes?