微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift 注解 和java比照@attribute name

Attributes provide more @R_73_4045@ion about a declaration or type. There are two kinds of attributes in Swift,those that apply to declarations and those that apply to types.

You specify an attribute by writing the @ symbol followed by the attribute’s name and any arguments that the attribute accepts:

  1. @attribute name
  2. @attribute name(attribute arguments)

Some declaration attributes accept arguments that specify more @R_73_4045@ion about the attribute and how it applies to a particular declaration. These attribute arguments are enclosed in parentheses,and their format is defined by the attribute they belong to.

 

  1. @dynamicmemberLookup
  2. struct DynamicStruct {
  3. let dictionary = ["someDynamicmember": 325,
  4. "someOtherMember": 787]
  5. subscript(dynamicmember member: String) -> Int {
  6. return dictionary[member] ?? 1054
  7. }
  8. }
  9. let s = DynamicStruct()
  10. // Using dynamic member lookup
  11. let dynamic = s.someDynamicmember
  12. print(dynamic)
  13. // Prints "325"
  14. // Calling the underlying subscript directly
  15. let equivalent = s[dynamicmember: "someDynamicmember"]
  16. print(dynamic == equivalent)

 

https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#grammar_attribute-argument-clause

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐