planc
planc

Reputation: 1

swift and sharedapplication

first post!

i've been working with swift for a while now, but decided to move some of my code to using shared variables and objects. I'm having a fundamental issue with being able to reference appDelegate.SharedApplication().delegate. Even with a basic test application (to see if I could see any fundamental problems), I cannot get a reference to the shared variable -

 // AppDelegate.swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

let info: String = "test"
}

trying to add - "let ref = UIApplication.sharedApplication().delegate as appDelegate" in another class complains of use of undeclared type app delegate.

removing that cast allows that, but once I try to create another variable reference to the info string, complains of no member named ref.

this seems such an obvious and confusing issue that I thought it time to ask for an answer :) all i want is to be able to use the appdelegate for controlling cllocationmanager and storing the return data in a variable for a view controller class to refer to.

xcode 6.1.1

cheers

Upvotes: 0

Views: 609

Answers (1)

Mundi
Mundi

Reputation: 80265

Maybe you are confusing the compiler because you are not using the proper case (upper or lower) when referring to variables or classes.

A class starts with an UpperCase letter.
Any variable starts with a lowerCase letter.

While this is not a rule for variables, it is a well-heeded convention.

Thus:

let stringFromDelegate =
 (UIApplication.sharedApplication() as AppDelegate).info

Upvotes: 0

Related Questions