How to wait for a function to end on iOS/Swift, before starting the second one

后端 未结 3 1240
囚心锁ツ
囚心锁ツ 2020-12-09 11:21

I basically have to methods, which are being called in my viewDidLoad. The first one gets the user\'s search preferences and saves the preferences to variables at the top. A

3条回答
  •  余生分开走
    2020-12-09 12:16

    Okay I've found an solution. I basically called the function at the end of the first one.

    So basically:

        var searchLocation = String()
        var searchLocationCoordinates = [String:Double]()
        var searchRange = Int()
    
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Gets the user's search preference
            getTheSearchLocationAndRange()
        }
    
        func getTheSearchLocationAndRange() {
        // Code for getTheSearchLocationAndRange()
    
        loadDataFromDatabase()
        }
    
        func loadDataFromDatabase(){
        // Code for loadDataFromDatabase()
        }
    

提交回复
热议问题