MeV
MeV

Reputation: 3958

How to pass parameters from appDelegate to ViewController?

I need to pass some parameters from the appDelegate to a viewController before loading it.

This is the code i'm trying to use (in the appDelegate.swift):

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let secondView = storyboard.instantiateViewControllerWithIdentifier("tab") as UITabBarController
secondView.variable = "xxxx"
self.window?.rootViewController = secondView;

but the compiler shows the following error:

UITabBarController does not have a member named 'variable'

Even thought, in the TabBarController class (TabBarController.swift) i have the following:

import UIKit
class TabBarController: UITabBarController {
var variable:String!
...etc

What's the error? Please give a clear explanation as i'm a beginner in Swift. Thank you very much!!

Upvotes: 1

Views: 1256

Answers (2)

dann_s_g
dann_s_g

Reputation: 21

Your second line should be

let secondView = storyboard.instantiateViewControllerWithIdentifier("tab") as TabBarController

Upvotes: 1

Kreiri
Kreiri

Reputation: 7850

You have TabBarController, but you instantiate as UITabBarController.

Upvotes: 2

Related Questions