Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
feature: rehabilitates the HasDisposeBag protocol #49
In Swift, struct is a value type which means memory handled in stack for struct, not in heap (like class as reference type) which indicate life cycle and reusability of a struct instance handled by swift compiler. When compiler is going reuse of an instance then associated bag also moving with it. So my question is what will happen in the following case:
and that struct adopted
My point could be wrong, I just want to verify. Let's discuss.
I get your point. When Struct B will be instantiated, Swift will reuse the stack allocated for A and use its associated DisposeBag ? We do net get a brand new DisposeBag.
Hi guys, Greg Parker (from the swift-dev mailling list) has answered my email. He thinks this is not safe to use objc_setAssociatedObject() as well as objc_sync_enter/exit. I think I will modify the protocol to add a :class conformance (protocol HasDisposeBag: class).