Passing Data from App delegate to View Controller

前端 未结 4 874
慢半拍i
慢半拍i 2020-12-05 09:55

I need to Pass an string from App delegate to my Initial View Controller , Can somebody listed me the best way to do it , also i tried to Save and Retrieve using NS user De

4条回答
  •  难免孤独
    2020-12-05 10:25

    Here it is for Swift:

    View Controller

    let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
    

    Furthermore, if you have an object that you want to pass between view controllers (for example, I had CloudKit data I wanted to share) add this to the App Delegate:

        /* Function for any view controller to grab the instantiated CloudDataObject */
    func getCloudData() ->CloudData{
        return cloudDataObject
    }
    

    Then back in the View Controller

    var model : CloudData = self.appDelegate.getCloudData()
    

提交回复
热议问题