1

I used to initiate a singleton class that is used to download JSON data in Swift 2.3 as follows

class Data {

class var sharedInstance: Data {

struct Static {
    static var instance: Data?
    static var token: dispatch_once_t = 0
        }

    dispatch_once(&Static.token) {
        Static.instance = Data()
   }

    return Static.instance!
}

I have updated to Xcode 8 and the old code is converted to

class Data {

private static var __once: () = {
        static.instance = Data()
    }()

class var sharedInstance: Data {

    struct Static {
        static var instance: Data?
        static var token: Int = 0
    }

    _ = Data.__once

    return Static.instance!
}

But now it is giving an error saying "expected declaration" at static.instance = Data().

I would be glad if anyone can tell me how to fix the error. At the same time what changes were made in Swift 3 with respect to Singleton class.

raja
  • 79
  • 5
  • This is not a duplicate. the question that was mentioned here does not talk about swift 3. I want the solution for swift 3 – raja Sep 27 '16 at 10:53

0 Answers0