Swift3.0 使用YTKNetwork网络框架

cocopods导入YTKNetwork 网络框架


在appdelegate.swift文件中的代码


Swift3.0 使用YTKNetwork网络框架_第1张图片

请求继承自YTKquest

#import

@interfaceWYCooperationApi :YTKRequest

@end

.m文件中内容是

#import"WYCooperationApi.h"

@implementationWYCooperationApi

- (NSString*)requestUrl {

return@"/Public/getCooperations";

}

- (YTKRequestMethod)requestMethod {

returnYTKRequestMethodGET;

}

- (id)requestArgument {

return@{

};

}

//-(NSDictionary *)requestHeaderFieldValueDictionary

//{

//NSString *str1 = [[CIUserManagerShared sharedInstance] userModel].authcode;

//NSString *str2 = [[CIUserManagerShared sharedInstance] userModel].userid;

//NSDictionary *dict = @{@"authcode":str1,@"userid":str2};

//return dict;

//}

- (id)jsonValidator {

return@{

};

}

@end

swift调用OC文件时 需要使用桥接文件 将相关的OC类 桥接

swift调用网络请求时是这样的:

//请求网络请求

letapi =WYCooperationApi()

api.startWithCompletionBlock(success: { (request)in

print(request.responseJSONObject??"")

}) { (request)in

print(request.responseJSONObject??"")

}

这里有一个坑点 我们这边后台配置json 数据的时候 设置为text/html格式的json数据 这在AFNetwork框架中使用 是会报错的 所以 还需要更改请求的类型

这样YTKNetwork 网络框架就可以在swift下正常的使用了

你可能感兴趣的:(Swift3.0 使用YTKNetwork网络框架)