Search code examples
objective-cswiftblockclass-methodalamofire

Objective C eqivalent Swift code?


This is a class method and I am passing block as one of the argument So basically how pass blocks in swift?

+ (NSURLSessionDataTask *)getAllSongIfo:(NSDictionary *)userInfo withBlock:(void (^)(NSArray *songInfos, NSError *error))block;

Solution

  • Swift equivalent:

    func getAllSongIfo(userInfo: NSDictionary, withBlock block:((NSArray?, NSError?) -> Void)) -> NSURLSessionDataTask
    

    If you want a class method you need to add the class keyword like:

    class func getAllSongIfo(userInfo: NSDictionary, withBlock block:((NSArray?, NSError?) -> Void)) -> NSURLSessionDataTask