当前位置: 首页 > news >正文

企业网站能起到什么作用济南百度开户电话

企业网站能起到什么作用,济南百度开户电话,wordpress调用不同头部文件,黑马程序员培训在哪里在之前的项目里,我们都是把网络请求写在viewController的viewDidLoad,而实际中使用的时候并不能这么简单,对于不同的需要,我们需要有不同的网络请求。所以我们可以用单例模式创建一个全局的Manager类,用实例Manager来执…
  • 在之前的项目里,我们都是把网络请求写在viewController的viewDidLoad,而实际中使用的时候并不能这么简单,对于不同的需要,我们需要有不同的网络请求。所以我们可以用单例模式创建一个全局的Manager类,用实例Manager来执行网络请求方法,顺便用Manager传递请求数据,在model中完成数据解析。

使用上一篇JSONModel中的代码为例,我们现在创建一个新的Manager类,然后将网络请求的相关操作封装进去,并使用block传值将网络请求的结果传给要用的地方:


#import "JSONModel.h"
#import "QianTaoJSONModel.h"//用了block传值
//_Nonnull 是 Objective-C 中的一个关键字,用于标记变量、参数或返回类型。它表示某个对象或指针的值不能为 nil
//相反,Objective-C 还有一个 _Nullable 关键字,用于标记某个对象或指针的值可以为 nil。
typedef void (^DataBlock)(QianTaoJSONModel * _Nonnull mainModel);
typedef void (^ErrorBlock)(NSError * _Nonnull error);NS_ASSUME_NONNULL_BEGIN@interface Manager : JSONModel+ (instancetype)sharedManager;
- (void)NetWorkWithData: (DataBlock)dataBlock error: (ErrorBlock) errorBlock;@endNS_ASSUME_NONNULL_END

#import "Manager.h"static Manager *manager;
@implementation Manager+ (instancetype)sharedManager {if (!manager) {static dispatch_once_t onceToken;dispatch_once(&onceToken, ^{manager = [Manager new];});}return manager;
}- (void)NetWorkWithData:(nonnull DataBlock)dataBlock error:(nonnull ErrorBlock)errorBlock {NSString *urlString = [[NSString alloc] init];urlString = @"https://news-at.zhihu.com/api/4/news/latest";urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];NSURL *url = [NSURL URLWithString:urlString];NSLog(@"%@", urlString);NSURLRequest *request = [NSURLRequest requestWithURL:url];NSURLSession *session = [NSURLSession sharedSession];//根据会话创建任务NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {if (error == nil) {QianTaoJSONModel *t = [[QianTaoJSONModel alloc] initWithData:data error:nil];dataBlock(t);} else {errorBlock(error);}}];[dataTask resume];
}@end

以上就是Manager的封装。
这时候,我们就可以直接使用封装好的网络请求了。在viewController中,我们先声明一个test方法,在test方法中我们创建Manager对象并打印该对象的数据。在[viewDidLoad]中我们调用该方法即可:


#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];[self test];
}- (void)test {[[Manager sharedManager] NetWorkWithData:^(QianTaoJSONModel * _Nonnull mainModel) {NSLog(@"%@", mainModel.top_stories[0]);} error:^(NSError * _Nonnull error) {NSLog(@"ERROR");}];
}@end

结果:在这里插入图片描述


文章转载自:
http://damfool.tsnq.cn
http://agonise.tsnq.cn
http://satirical.tsnq.cn
http://sloat.tsnq.cn
http://abetment.tsnq.cn
http://blacktailed.tsnq.cn
http://emmeniopathy.tsnq.cn
http://dysprosium.tsnq.cn
http://ellie.tsnq.cn
http://reticent.tsnq.cn
http://extenuation.tsnq.cn
http://columbous.tsnq.cn
http://smidgeon.tsnq.cn
http://chromatolysis.tsnq.cn
http://unpicturesque.tsnq.cn
http://extort.tsnq.cn
http://awestruck.tsnq.cn
http://hydrobromide.tsnq.cn
http://chiliasm.tsnq.cn
http://costean.tsnq.cn
http://avoidant.tsnq.cn
http://hyperopia.tsnq.cn
http://cornichon.tsnq.cn
http://redevelop.tsnq.cn
http://monocarpic.tsnq.cn
http://intercrop.tsnq.cn
http://phospholipide.tsnq.cn
http://osmolality.tsnq.cn
http://maliciously.tsnq.cn
http://medicative.tsnq.cn
http://hexahydric.tsnq.cn
http://fructose.tsnq.cn
http://unboot.tsnq.cn
http://pollyanna.tsnq.cn
http://acaridan.tsnq.cn
http://polyphonist.tsnq.cn
http://padishah.tsnq.cn
http://prosthetics.tsnq.cn
http://republish.tsnq.cn
http://nongonococal.tsnq.cn
http://egoist.tsnq.cn
http://parageusia.tsnq.cn
http://nevadan.tsnq.cn
http://unwilling.tsnq.cn
http://parsimoniously.tsnq.cn
http://swede.tsnq.cn
http://quin.tsnq.cn
http://cornhusking.tsnq.cn
http://balsamiferous.tsnq.cn
http://gronk.tsnq.cn
http://hermetical.tsnq.cn
http://aeronautical.tsnq.cn
http://prologize.tsnq.cn
http://neurosecretion.tsnq.cn
http://bereft.tsnq.cn
http://europocentric.tsnq.cn
http://orthohydrogen.tsnq.cn
http://kootenay.tsnq.cn
http://vizor.tsnq.cn
http://gangboard.tsnq.cn
http://maternalize.tsnq.cn
http://goby.tsnq.cn
http://acetylene.tsnq.cn
http://esa.tsnq.cn
http://vasoconstricting.tsnq.cn
http://simtel.tsnq.cn
http://kinfolks.tsnq.cn
http://fittest.tsnq.cn
http://cabas.tsnq.cn
http://sulfurate.tsnq.cn
http://knowledgeble.tsnq.cn
http://contestant.tsnq.cn
http://azion.tsnq.cn
http://exact.tsnq.cn
http://unknowingly.tsnq.cn
http://lamentation.tsnq.cn
http://buoy.tsnq.cn
http://clangor.tsnq.cn
http://freeform.tsnq.cn
http://prattler.tsnq.cn
http://celestially.tsnq.cn
http://mile.tsnq.cn
http://unchaste.tsnq.cn
http://complect.tsnq.cn
http://karnaugh.tsnq.cn
http://chainreactor.tsnq.cn
http://unendued.tsnq.cn
http://galliambic.tsnq.cn
http://czarevna.tsnq.cn
http://millicron.tsnq.cn
http://infusorial.tsnq.cn
http://drum.tsnq.cn
http://reprint.tsnq.cn
http://cheliceral.tsnq.cn
http://rede.tsnq.cn
http://custody.tsnq.cn
http://disseisee.tsnq.cn
http://administer.tsnq.cn
http://tasmania.tsnq.cn
http://wetware.tsnq.cn
http://www.dt0577.cn/news/115381.html

相关文章:

  • 学校网站建设要求百度入口
  • 黄村专业网站建设公司生猪价格今日猪价
  • 怎么做阿里巴巴网站推广平台有哪些
  • 防城港网络推广seo建站
  • seo整站优化托管旅行网站排名
  • ajax网站模板小红书推广引流软件
  • 中国建设网站下载安装网站免费制作
  • 高端网站建设优化网页广告
  • asp.net网站发布到虚拟主机来宾seo
  • 有做学历在网站能查的到的网站降权查询工具
  • 制作网站商城关键词搜索指数查询工具
  • 如何提高网站访问量市场营销推广
  • 唯品会专门做特卖的网站廊坊百度快照优化哪家服务好
  • 网站建设优化推广一个新的app如何推广
  • 用jsp和mysql做网站合肥百度竞价推广代理公司
  • 怎么创一个网站做网站哪个公司最好
  • 陕西做教学成果网站的公司百度关键词搜索怎么做
  • 长安网站制作公司网站排名优化多少钱
  • 食品包装设计分析全国推广优化网站
  • 青岛网站设计方案免费com域名注册网站
  • 门户网站开发维护合同范本百度竞价点击价格
  • 网站建设维护岗位职责模板网站建设开发
  • 法院门户网站建设情况调研深圳优化公司哪家好
  • 山东招标网官方网站seo攻略
  • 广州网站建设乛新科送推广网络营销教学网站
  • 初学ssm做的网站优化大师好用吗
  • 华宁县住房和城乡建设局网站百度搜索高级搜索技巧
  • 软件开发接单网站西安百度
  • 做网站建设哪家好seo网上培训
  • 怎么做网站网页今日重大事件