Android App Development
iOS 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 188.8.131.52 release ready!
Owner and Founder. Opencart
In this post, we are going to discuss the primary associated types which are introduced in Swift 5.7.
In Swift 5.7, we can specify primary associated types with protocols.
So let’s discuss the Primary Associated Types in detail.
The primary associated types are lot like the generics, with these we can specify the type for a given associated type as a generic constraint.
For Collection, the Swift library added a primary associated type for the Element associated type.
Let’s take a look at how a protocol defines a primary associated type.
In the above code, you can see that the protocol have multiple associated types, but as the Element is primary associated type it is not written between <>
We can use the above protocol in our code as below:
In above code we are using ‘some’ keyword which is more descriptive. The above code snippet is equivalent to below code.
Note that this also works with the ‘any’ keyword. For example, if we want to store our movie on our Movies, we could write the following code:
I assume that you have knowledge about the ‘some’ and ‘any’ keywords. However, You can visit my blog if you want to read about the ‘some’ and ‘any’ keywords in Swift.
In conclusion, with primary associated types we can write descriptive and much more powerful code
Please visit the link for more information on primary associated types by donnywals
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.
It was a successful collaboration. The Mobikul team provided the client everything they needed in a timely and high-quality manner. They were very professional, reliable, and accessible during the entire process. The client also saw no room for any improvements in the vendor's performance.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.