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

杭州网站设计公司价格柳州哪家公司做网站好

杭州网站设计公司价格,柳州哪家公司做网站好,中国纪检监察报在线阅读,企业网站建设报价表Combine 系列 Swift Combine 从入门到精通一Swift Combine 发布者订阅者操作者 从入门到精通二Swift Combine 管道 从入门到精通三Swift Combine 发布者publisher的生命周期 从入门到精通四Swift Combine 操作符operations和Subjects发布者的生命周期 从入门到精通五Swift Com…Combine 系列 Swift Combine 从入门到精通一Swift Combine 发布者订阅者操作者 从入门到精通二Swift Combine 管道 从入门到精通三Swift Combine 发布者publisher的生命周期 从入门到精通四Swift Combine 操作符operations和Subjects发布者的生命周期 从入门到精通五Swift Combine 订阅者Subscriber的生命周期 从入门到精通六Swift 使用 Combine 进行开发 从入门到精通七Swift 使用 Combine 管道和线程进行开发 从入门到精通八Swift Combine 使用 sink, assign 创建一个订阅者 从入门到精通九Swift Combine 使用 dataTaskPublisher 发起网络请求 从入门到精通十Swift Combine 用 Future 来封装异步请求 从入门到精通十一 目的使用 Combine 的管道来显式地对异步操作进行排序 这类似于一个叫做 “promise chaining” 的概念。 虽然你可以将 Combine 处理的和其行为一致但它可能不能良好地替代对 promise 库的使用。 主要区别在于promise 库总是将每个 promise 作为单一结果处理而 Combine 带来了可能需要处理许多值的复杂性。 任何需要按特定顺序执行的异步或同步任务组都可以使用 Combine 管道进行协调管理。 通过使用 Future 操作符可以捕获完成异步请求的行为序列操作符提供了这种协调功能的结构。 通过将任何异步 API 请求与 Future 发布者进行封装然后将其与 flatMap 操作符链接在一起你可以以特定顺序调用被封装的异步 API 请求。 通过使用 Future 或其他发布者创建多个管道使用 zip 操作符将它们合并之后等待管道完成通过这种方法可以创建多个并行的异步请求。 如果你想强制一个 Future 发布者直到另一个发布者完成之后才被调用你可以把 future 发布者创建在 flatMap 的闭包中这样它就会等待有值被传入 flatMap 操作符之后才会被创建。 通过组合这些技术可以创建任何并行或串行任务的结构。 如果后面的任务需要较早任务的数据这种协调异步请求的技术会特别有效。 在这些情况下所需的数据结果可以直接通过管道传输。 此排序的示例如下。 在此示例中按钮在完成时会高亮显示按钮的排列顺序是特意用来显示操作顺序的。 整个序列由单独的按钮操作触发该操作还会重置所有按钮的状态如果序列中有尚未完成的任务则都将被取消。 在此示例中异步 API 请求会在随机的时间之后完成作为例子来展示时序的工作原理。 创建的工作流分步表示如下 步骤 1 先运行。步骤 2 有三个并行的任务在步骤 1 完成之后运行。步骤 3 等步骤 2 的三个任务全部完成之后再开始执行。步骤 4 在步骤 3 完成之后开始执行。 此外还有一个 activity indicator 被触发以便在序列开始时开始动画在第 4 步完成时停止。 UIKit-Combine/AsyncCoordinatorViewController.swift import UIKit import Combineclass AsyncCoordinatorViewController: UIViewController {IBOutlet weak var startButton: UIButton!IBOutlet weak var step1_button: UIButton!IBOutlet weak var step2_1_button: UIButton!IBOutlet weak var step2_2_button: UIButton!IBOutlet weak var step2_3_button: UIButton!IBOutlet weak var step3_button: UIButton!IBOutlet weak var step4_button: UIButton!IBOutlet weak var activityIndicator: UIActivityIndicatorView!var cancellable: AnyCancellable?var coordinatedPipeline: AnyPublisherBool, Error?IBAction func doit(_ sender: Any) {runItAll()}func runItAll() {if self.cancellable ! nil { // 1print(Cancelling existing run)cancellable?.cancel()self.activityIndicator.stopAnimating()}print(resetting all the steps)self.resetAllSteps() // 2// driving it by attaching it to .sinkself.activityIndicator.startAnimating() // 3print(attaching a new sink to start things going)self.cancellable coordinatedPipeline? // 4.print().sink(receiveCompletion: { completion inprint(.sink() received the completion: , String(describing: completion))self.activityIndicator.stopAnimating()}, receiveValue: { value inprint(.sink() received value: , value)})}// MARK: - helper pieces that would normally be in other files// this emulates an async API call with a completion callback// it does nothing other than wait and ultimately return with a boolean valuefunc randomAsyncAPI(completion completionBlock: escaping ((Bool, Error?) - Void)) {DispatchQueue.global(qos: .background).async {sleep(.random(in: 1...4))completionBlock(true, nil)}}/// Creates and returns pipeline that uses a Future to wrap randomAsyncAPI/// and then updates a UIButton to represent the completion of the async/// work before returning a boolean True./// - Parameter button: button to be updatedfunc createFuturePublisher(button: UIButton) - AnyPublisherBool, Error { // 5return FutureBool, Error { promise inself.randomAsyncAPI() { (result, err) inif let err err {promise(.failure(err))} else {promise(.success(result))}}}.receive(on: RunLoop.main)// so that we can update UI elements to show the completion// of this step.map { inValue - Bool in // 6// intentionally side effecting here to show progress of pipelineself.markStepDone(button: button)return true}.eraseToAnyPublisher()}/// highlights a button and changes the background color to green/// - Parameter button: reference to button being updatedfunc markStepDone(button: UIButton) {button.backgroundColor .systemGreenbutton.isHighlighted true}func resetAllSteps() {for button in [self.step1_button, self.step2_1_button, self.step2_2_button, self.step2_3_button, self.step3_button, self.step4_button] {button?.backgroundColor .lightGraybutton?.isHighlighted false}self.activityIndicator.stopAnimating()}// MARK: - view setupoverride func viewDidLoad() {super.viewDidLoad()self.activityIndicator.stopAnimating()// Do any additional setup after loading the view.coordinatedPipeline createFuturePublisher(button: self.step1_button) // 7.flatMap { flatMapInValue - AnyPublisherBool, Error inlet step2_1 self.createFuturePublisher(button: self.step2_1_button)let step2_2 self.createFuturePublisher(button: self.step2_2_button)let step2_3 self.createFuturePublisher(button: self.step2_3_button)return Publishers.Zip3(step2_1, step2_2, step2_3).map { _ - Bool inreturn true}.eraseToAnyPublisher()}.flatMap { _ inreturn self.createFuturePublisher(button: self.step3_button)}.flatMap { _ inreturn self.createFuturePublisher(button: self.step4_button)}.eraseToAnyPublisher()} }runItAll 协调此工作流的进行它从检查当前是否正在执行开始。 如果是它会在当前的订阅者上调用 cancel()。resetAllSteps 通过遍历所有表示当前工作流状态的按钮并将它们重置为灰色和未高亮以回到初始状态。 它还验证 activity indicator 当前未处于动画中。然后我们开始执行请求首先开启 activity indicator 的旋转动画。使用 sink 创建订阅者并存储对工作流的引用。 被订阅的发布者是在该函数外创建的允许被多次复用。 管道中的 print 操作符用于调试在触发管道时在控制台显示输出。每个步骤都由 Future 发布者紧跟管道构建而成然后立即由管道操作符切换到主线程然后更新 UIButton 的背景色以显示该步骤已完成。 这封装在 createFuturePublisher 的调用中使用 eraseToAnyPublisher 以简化返回的类型。map 操作符用于创建并更新 UIButton作为特定的效果以显示步骤已完成。创建整个管道及其串行和并行任务结构是结合了对 createFuturePublisher 的调用以及对 flatMap 和 zip 操作符的使用共同完成的。 另请参阅 通过包装基于 delegate 的 API 创建重复发布者使用此代码的 ViewController 在 github 的项目中 UIKit-Combine/AsyncCoordinatorViewController.swift. 参考 https://heckj.github.io/swiftui-notes/index_zh-CN.html 代码 https://github.com/heckj/swiftui-notes
http://www.hkea.cn/news/14485612/

相关文章:

  • 网站建设文编企点官网
  • jquery 购物网站厦门百度网站建设
  • 电商网站报价重庆seo入门教程
  • 为您打造高端品牌网站重置wordpress密码
  • 专业网站建设咨询第一家中文商务网站
  • 电商网站开发步骤重庆网站建设公司销售
  • 建设银行手机官方网站下载安装网站模板图片
  • 网站开发商城1688产品经理如何看待网站开发
  • 保险网站排名广告设计与制作需要学什么
  • wordpress站点取名开发比较实用的软件
  • 网站建设保密条款wordpress 做社区
  • 深圳企业网站制作怎么开电商网店
  • 企业网站的短视频中心模板为什么要建设应急管理网站
  • 网站建设 尚瑞科技做网站制作的公司
  • 漯河市城市建设投资公司网站工信部网站备案密码
  • 网站语言切换前端可以做么购物网站源码
  • 成都市建设工程施工安监站网站鄂州seo厂家
  • 佛山网站搜索引擎优化网站开发过程会遇到的问题
  • 用wordpress仿a站网至普的营销型网站建设
  • 网站后台上传图片做难吗wordpress 主题小工具
  • 章丘公司做网站做便民网站都需要提供什么
  • 广州建站推广emeinet亿玫网站建设
  • mvc5做博客网站100m的光纤可以做网站吗
  • asp室内装修装潢网站源码wordpress 投稿审核
  • 网站开发广告宣传语霸气的网络公司名字
  • 旅游类网站开发开题报告范文WordPress怎么添加音乐
  • 如何注册一个设计网站郑州做定制网站的公司哪家好
  • 申请一个网站需要多少钱有没有教做韩餐的网站
  • 郑州网站推广培训网页视频下载插件哪个好用
  • 网站模板免费推荐自建社区网站