2

I am trying to convert my objectiveC application into swift and i am able to do it most of the things but here is some confusion ...

My ObjectiveC code is

-(void)getResponseFromURL:(NSString *)strURL 
  withParams:(NSMutableDictionary *)dictParams  
  success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, bool isSuccess))blockSuccess  
  failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))blockFailure  
  showLoader:(BOOL)isShowDefaultLoader  
  showAnimated:(BOOL)isShowLoaderAnimated hideLoader:(BOOL)isHideDefaultLoader
  { //some code here }  

My Swift code

func getResponseFromURL(strURL: String, withParams dictParams:Dictionary,  
Success:(operation:AFHTTPRequestOperation, responseobject:AnyObject, isSucces:Bool)->void, 
Failure:(operation:AFHTTPRequestOperation, error:NSError)->void,
showLoader isShowDefaultLoader:Bool,
showAnimated isShowLoaderAnimated:Bool, hideLoader isHideDefaultLoader:Bool){
    // Some code here
}

but it gives me some error
enter image description here

I think i missed some tricks...but i don't know what was that...
So how to get rid of this error?

Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108

3 Answers3

3
  1. In Swift, use Void, not void
  2. Dictionary in Swift is Generic, you need specify it as Dictionary<AnyObject, AnyObject> or use NSDictionary directly. You can convert NSDictionary to Swift Dictionary following this answer

Update:

Thanks to Aviel Gross, use [AnyObject: AnyObject] instead of Dictionary<AnyObject, AnyObject>

As code of WenchenHuang shows, () is the same with Void in Swift, both represent empty tuple.

Community
  • 1
  • 1
Elliot Li
  • 452
  • 1
  • 5
  • 17
1

In Swift it's Void. The "V" must be uppercase.

Luca Angeletti
  • 58,465
  • 13
  • 121
  • 148
1
  func getResponseFromURL(strURL: String, withParams dictParams:NSDictionary,
        Success:(operation: AFHTTPRequestOperation, responseobject:AnyObject, isSucces:Bool)->(),
        Failure:(operation: AFHTTPRequestOperation, error:NSError)->(),
        showLoader isShowDefaultLoader:Bool,
        showAnimated isShowLoaderAnimated:Bool, hideLoader isHideDefaultLoader:Bool){
            // Some code here
    }
Leo
  • 24,596
  • 11
  • 71
  • 92