0
func loadMoreData(offset: Int, completion: (result: [ArtistJSONMapper]?) -> Void) {

    var fetchedData = [ArtistJSONMapper]()
    let pageNum: Int = offset/paging.limit

    // Calling the json fetch to obtain data

    JSONFetch.jsonTest() { (fetched, error) -> Void in
        if(fetched != nil) {
            fetchedData = fetched!
            //self.tableView.reloadData()

        } else {
            println("error - \(error)")
        }
    }

    println("Fetched data count is \(fetchedData.count)")
    completion(result: fetchedData.count > 0 ? fetchedData : nil)

}

I am using AlamofireObjectMapper to fetch data using the method JSONFetch.jsonTest(). Now the problem is how do I call this loadMoreData from my controller?

1

1 Answer 1

0

I do implementing trailing closure here

loadMoreData(2){ (result) in

//after completion of your work this closure gets called
 println("your return \(result)")


}
1
  • Thanks I figured it out before you commented. :) loadMoreData(offset, completion: { (fetched) -> Void in if let fetchedData = fetched { println("Fetched Data(fetchedData.count)") completion(fetchedData) } }) I did it using like this Aug 4, 2015 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.