简体   繁体   English

Swift 组合:PassthroughSubject UnsafeMutablePointer

[英]Swift Combine: PassthroughSubject UnsafeMutablePointer

I have the following implementation:我有以下实现:

var flag = CurrentValueSubject<Bool,Never>(false)
    var flagChange = PassthroughSubject<Bool,Never>()
    var subscriptions = Set<AnyCancellable>()
    
    init() {
        flagChange.sink { [unowned self] value in
            print("value \(value)")
            print("current value \(self.flag)")
        } receiveValue: { [unowned self] value in
            print("value received \(value)")
            self.flag.send(value)
        }.store(in: &subscriptions)
    }

When I execute in the playground I'm getting this error/warnings:当我在操场上执行时,我收到此错误/警告:

在此处输入图片说明

Any of you knows why and how can avoid it or fix it?你们中的任何人都知道为什么以及如何避免或修复它?

I'll really appreciate your help.我会非常感谢你的帮助。

It's not an error, and it's not a warning.这不是错误,也不是警告。 It's the reported QuickLook value of your myClass.flagChange.send(true) statement.这是myClass.flagChange.send(true)语句的报告 QuickLook Your let myClass = MyClass() has a pretty weird-looking QuickLook value too.您的let myClass = MyClass()也有一个非常奇怪的 QuickLook 值。 It's mysterious, for sure, but if it bothers you, don't look at it.当然,它很神秘,但如果它困扰您,请不要看它。 Your code itself runs fine and the printed outputs are just what you would expect.您的代码本身运行良好,打印的输出正是您所期望的。 Playgrounds are strange places, and you are using one to look at the value of a statement that doesn't really have a value. Playgrounds 是一个奇怪的地方,你正在使用它来查看一个没有真正价值的语句的价值。 So just relax and move on.所以只要放松并继续前进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM