1

I have a problem to use a method developed in Swift that I want to use in objective C.

Swift 4 Class: in this function I retrieve the information of the user (like userNumber, secretCode)

@objc class MySwiftClass: HPTableViewController { func loadMemberProfil(completion: ((_ sub : [String: AnyObject]) -> Void)!) { //API get profile and Bearer token let token = HPWSLoginManager.shared().saveSuccessResponse.token let url = URL(string: "http://51.38.36.76:40/api/v1/profile") var request = URLRequest(url: url!) request.httpMethod = "GET" request.addValue("Bearer \(token!)", forHTTPHeaderField: "Authorization") //get information in token URLSession.shared.dataTask(with: request) { (data, response, error) in guard let data = data else { return } do { let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! [String: AnyObject] let sub = json["sub"] as! [String: AnyObject] if completion != nil{ completion(sub) } } catch { print("error") } }.resume() } } 

for example at the end of the function I get

 sub["usernumber"]! // print +224625259239 sub["secretcode"]! // print $2a$08$DIrq1iKnjkkY4KgI3Mqy7.aWC39m2aFMncfJSkom9l0yaXhGlH35m 

Objective-C implementation (Objective-C.m) I want to display this information above

#import "ProjectName-Swift.h" MySwiftClass* userProfil = [[MySwiftClass alloc]init]; [userProfil loadMemberProfil: ^(NSDictionary *sub) { // No visible @interface for 'MySwiftClass' declares the selector 'loadMemberProfil:' userNumber = sub[@"usernumber"]; secretCode = sub[@"secretcode"]; }]; 

but I get this error message No visible @interface for 'MySwiftClass' declares the selector 'loadMemberProfil:' could someone help me? please :)

2
  • I think you want [userProfil loadMemberProfileCompletion:...] Commented Oct 24, 2018 at 15:27
  • Instead of @objc, @use objcMembers Commented Oct 24, 2018 at 15:32

1 Answer 1

3

You need

@objcMembers class MySwiftClass: UIViewController { --- } 

OR

@objc func loadMemberProfil(completion: ((_ sub : [String: AnyObject]) -> Void)!) { --- } 

With this call

[userProfil loadMemberProfilWithCompletion:^(NSDictionary*dic ) { }]; 
Sign up to request clarification or add additional context in comments.

1 Comment

ThX it's Work :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.