1

Trying to populate a table view with data pulled from firebase. I initially was able to run the app with static data but when I implemented the pull from firebase I started getting the error "Unexpected non-void return value in void function" after I return the sections array.

import Foundation
import Firebase 

class SectionsData {

var users = [User]()
var currentUser: User!
var userKey: String?

func getSectionsFromData() -> [Section] {


    DataService.ds.CURRENT_USER_REF.observeEventType(.Value, withBlock: {snapshot in

        print(snapshot.value)

        self.users = []

        if let currentUserDict = snapshot.value as? Dictionary<String, AnyObject> {

            let key = snapshot.key
            let currentUser = User(userKey: key, dictionary: currentUserDict)
            self.users.append(currentUser)

            var sectionsArray = [Section]()

            let jobType = Section(title: "Type of Job I'm looking for:", objects: ["A really cool one"])
            let bio = Section(title: "Bio:", objects: [(currentUserDict["userBio"] as? String)!])
            let atts = Section(title: "What I bring to the table:", objects: [(currentUserDict["userAtt1"] as? String)!, (currentUserDict["userAtt2"] as? String)!, (currentUserDict["userAtt3"] as? String)!])


            sectionsArray.append(jobType)
            sectionsArray.append(bio)
            sectionsArray.append(atts)

            return sectionsArray //error occurs here

        }



    })

Can anyone help with this? Thank you in advance!

ryanbilak
  • 383
  • 1
  • 2
  • 13
  • You have a conceptual issue with synchronous/asynchronous functionality. – trojanfoe May 18 '16 at 18:32
  • Hey thank you! I'm new so iOS development, can you elaborate? – ryanbilak May 18 '16 at 18:37
  • It's a bit complex but that block will fire at some point in the future and therefore the method that sets it up won't have an array to return at that point in time. You need to read up on this (it's not unique to Objective-C or swift) and restructure your code. – trojanfoe May 18 '16 at 19:00
  • Ok thanks, can you tell me what I should search for to get the relevant information on this? – ryanbilak May 18 '16 at 19:18
  • See [this answer](http://stackoverflow.com/questions/37104816/finish-asynchronous-task-in-firebase-with-swift/37124220#37124220). I would strongly encourage you, if you haven't already, to go through all of the iOS getting started guides on the Firebase website. – Jay May 18 '16 at 22:13

0 Answers0