Leanpub Header

Skip to main content

用测试用例探索 Combine 的工作机制

在这个小册子里,我们会尝试用一些测试用例探寻 Combine 的工作机制。而整理这些内容的动力,则源于开发泊学 App 的时候,把代码迁移到 Combine 过程中时遇到的一个 Bug。因此,这不是一个 Combine 的入门教程,所以,确保你在继续之前,至少要体验过 Combine, 如果你还有 RxSwift4 的开发经验,就更好了:) 

Free With Membership

With Membership

Free!

$7.99

You pay

$0.00

Author earns

$0.00
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
About

About

About the Book

在这个小册子里,我们会尝试用一些测试用例探寻 Combine 的工作机制。而整理这些内容的动力,则源 于开发泊学 App 的时候,把代码迁移到 Combine 过程中时遇到的一个 Bug。至于这个 Bug 本身,我们会在这个册子的最后才向大家揭晓,因为只有到那个时候,你可能才真的能理 解我在说什么。相信我,如果你希望尝试使用 Combine 开发一些应用,理解我们接下来要 讨论的东西真的可以为你节约很多时间。 因此,这不是一个 Combine 的入门教程,所以,确保你在继续之前,至少要体验过 Combine, 如果你还有 RxSwift4 的开发经验,就更好了:) 

这本册子中用到的全部代码,都在这里。 除了文字内容之外,我们还为每一章内容录制了影片,它们也是完全免费的。影片的链接,

会放在每一章的开始,大家可以直接点击观看(无需注册)。 

Share this book

Categories

Author

About the Author

Mars

十年,我不在创业,就在创业的路上。

2005年,我开始步入IT行业。那个时候产品经理还没有“小CEO“的光环,也没有“产品狗”的苦逼,大部分程序员也都还认为自己就是写代码的。

而自己在那些年,跑过采访、写过稿子,憋过文案、搞过设计、做过硬件、写过软件、带过团队。既和朋友一起尝试过捞一把中关村上空漂浮的美元,也和传统行业的老板一起下乡共过事。

崔轶,男,北京人,儿立之年,无背景,也不是富二代。爱编程,C++死忠,酷爱操作系统内核、数据结构、系统开发这些看似很死板的玩意儿;爱读书,唯爱技术书, 喜欢孟岩老师犀利幽默的笔风(感谢过去一起共事的岁月)、侯捷老师深厚的技术文学底蕴以及Stanley Lippman、Scotte Mayers、M. Josuttis这些大师对技术细节严谨、准确、实用的阐述。

正是这些爱好,使得完美融合了文学和技术东西,对我有一种特别的吸引力。每每遇之,则有相见恨晚的喜悦,读之,亦有“漫卷诗书喜欲狂”的快感。

因此,写代码和写书,打小就是人生中的一大乐事,希望更多人学会编程,爱上编程。

Contents

Table of Contents

写在前面

  1. 关于代码和影片
  2. 关于邀请码

Chapter One Combine 中的订阅和发布模型

  1. 影片地址
  2. Combine 中的发布者和订阅者
  3. 观察 Combine 的事件订阅模型
  4. What’s next?

模拟 Subscription 实现 - I

  1. 影片地址
  2. 一个完整的订阅发布模型
  3. 自定义 Subscription 实现
  4. What’s next?

模拟 Subscription 实现 - II

  1. 影片地址
  2. 自定义 Publisher
  3. What’s next?

模拟 Subscription 实现 - III

  1. 影片地址
  2. 自定义 CustomScan
  3. 通过单元测试验证模型
  4. What’s next?

让 CustomSubject 线程安全

  1. 影片地址
  2. AtomicBox
  3. CustomSuject 的线程安全性
  4. What’s next?

让 CustomSubject 线程安全

  1. 影片地址
  2. 共享 Subject
  3. 缓存计算出来的事件
  4. What’s next?

实现自定义的事件缓冲区 - I

  1. 影片地址
  2. 定义 Buffer
  3. 自定义 SubscriptionBehavior
  4. What’s next?

实现自定义的事件缓冲区 - I

  1. 影片地址
  2. BufferSubject
  3. 用单元测试验证结果
  4. What’s next?

有些意外的 Subject 生命周期

  1. 影片地址
  2. 从一个最自然的模型开始
  3. 不会自动取消的订阅者
  4. 一个不需要任何强引用的场景
  5. What’s next?

Combine 中的多重订阅 - I

  1. 影片地址
  2. 什么是多重订阅呢
  3. MergeSink
  4. What’s next?

Combine 中的多重订阅 - II

  1. 影片地址
  2. 从测试用例开始
  3. 无法“续命”的订阅
  4. What’s next?

Combine 事件供给机制的回顾

  1. 影片地址
  2. CustomDemandSink
  3. CustomDemandSink
  4. 编写测试用例
  5. What’s next?

Combine 中的异步事件调度

  1. 影片地址
  2. 一个形式上异步的测试用例
  3. 一个会丢事件的订阅场景
  4. 一个便于观察 Publisher 的方法
  5. 重新观察之前的丢消息场景
  6. 妥善使用 receive(on:) 的方法
  7. What’s next?

At Last

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub