Generics

作者: 幸运的小强本人 | 来源:发表于2016-03-06 22:45 被阅读3次

*Generics code enables you to write flexible, reusable functions and types that can work with any type, subject to requirements that you define. You can write code that avoids duplication and expresses its intent in a clear, abstracted manner.

Generics are one of the most powerful features of Swift, and much of the Swift standard library is built with generic code. In fact, you've been using generics throughout the Language Guide, even if you didn't realize it. For example, Swift's Array and Dictionary types are both generic collections. You can create an array that holds Int values, or an array that holds String values, or indeed an array for any other type that can be created in Swift.Similarly, you can create a dictionary to store values of any specified type, and there are no limitations on what that type can be.

相关文章

网友评论

      本文标题:Generics

      本文链接:https://www.haomeiwen.com/subject/inpakttx.html