Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 126.96.36.199 release ready!
After Swift 5.5 Apple introduced the Sendable and @Sendable in Swift.
Sendable and @Sendable in Swift address the problem of type-checking values passed between concurrency constructs and actor messages.
Let’s dive into the article.
We can pass the Sendable values from one concurrency domain to another.
For instance, you can pass a sendable value as the argument when calling an actor’s methods. Below can be marked as Sendable:
Here is an example of how integers support the Sendable protocol:
Creating a struct with a single value of type Int automatically conforms to Sendable.
If the generic type does not conform to Sendable, the compiler does not add implicit conformance.
Here is how we create a struct with conformance to Sendable.
Here is an example of enumeration.
The Sendable protocol and closure indicate whether the public API of the passed values passed thread-safe to the compiler. However, it also reduces the chances of the race around conditions.
Above all, there are cases in which the compiler does not add implicit conformance, we need to conform to the protocol manually.
For instance, the class that is immutable can conform to the Sendable protocol
In addition, the classes which are mutable need to be marked as @unchecked attribute to indicate our class is actually thread-safe due to internal locking mechanisms.
Above all, the Non-final class cannot conform to Sendable, we have to use @unchecked Sendable.
In conclusion, we can use @Sendable to tell the compiler that no extra synchronization is needed as all captured values in the closure are thread-safe.
For more details please visit here.
To read more articles please visit here.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.