类目标C的Swift完成处理程序

时间:2018-10-05 17:41:49

标签: objective-c swift

我很快要上这堂课

  @objc class NetworkManager: NSObject{
   var dataRepositories: [repositories]!
   static let shared = NetworkManager()

func request_repositories(_ completionHanlder: @escaping ()-> Void){
    Alamofire.request("https://api.github.com").responseJSON { (response) in
        let data = response.data
        // print(response)

        do{
            let r = try JSONDecoder().decode(repositories.self, from: data!)
            self.dataRepositories = [r]
             completionHanlder()

        }catch let error{
            print(error)
            return
        }
    }

}

我无法在目标c类中调用request_repositories

@interface ViewController ()
@property (strong, nonatomic) NetworkManager *man;


@end
@interface NetworkManager ()
-(void)request_repositories;
//-(repositories*)retornar;
@end


@implementation ViewController

 - (void)viewDidLoad {
   [super viewDidLoad];
     // Do any additional setup after loading the view, typically from a nib.
   self.man = [NetworkManager alloc];
   [self.man request_repositories];
   [[NetworkManager new] request_repositories];




  }


@end

我怀疑是否可以在目标c类c中调用完成处理程序,如果可以,我该怎么做,我是ios编程的新手,所以我对此表示怀疑,因为我没有这样做如果有人有更好的建议,知道如何在目标c中使用json

0 个答案:

没有答案