Attributes provide more information 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 information 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

swift 注解 (和java比照)@attribute name的更多相关文章

  1. 160919、使用AOP与注解记录Java日志

    有些时候,我想要把每个运行过的方法接收到的参数.返回值和执行时间等信息记录(通过slf4j 和 log4j)下来.在AspectJ.jcabi-aspects和Java注解的帮助下我实现了这个想法. ...

  2. Spring注解与Java元注解小结

    注解 Annotation 基于注解的开发,使得代码简洁,可读性高,简化的配置的同时也提高了开发的效率,尤其是SpringBoot的兴起,随着起步依赖和自动配置的完善,更是将基于注解的开发推到了新的高 ...

  3. 【转】Spring学习---Bean配置的三种方式(XML、注解、Java类)介绍与对比

    [原文]https://www.toutiao.com/i6594205115605844493/ Spring学习Bean配置的三种方式(XML.注解.Java类)介绍与对比 本文将详细介绍Spri ...

  4. 【JSON 注解】JSON循环引用2----JSON注解@JsonIgnoreProperties+JAVA关键字transient+后台对象与JSON数据的格式互相转化

    接着来说这个JSON循环引用的问题: 关于JSON格式的转化,其实关键就是这几个依赖: <!-- json --> <!-- 1号 --> <dependency> ...

  5. 使用XStream注解实现Java对象与XML互相转换的代码示例

    本文记录一下使用xstream这个api的注解特性对Java对象与XML字符串相互转换的一些代码示例.    我们很多人都处理过XML文件,也有很多非常成熟的第三方开源软件.如:jdom.dom4j等 ...

  6. Spring学习笔记1——IOC: 尽量使用注解以及java代码(转)

    在实战中学习Spring,本系列的最终目的是完成一个实现用户注册登录功能的项目. 预想的基本流程如下: 1.用户网站注册,填写用户名.密码.email.手机号信息,后台存入数据库后返回ok.(学习IO ...

  7. Spring学习笔记1——IOC: 尽量使用注解以及java代码

    在实战中学习Spring,本系列的最终目的是完成一个实现用户注册登录功能的项目. 预想的基本流程如下: 1.用户网站注册,填写用户名.密码.email.手机号信息,后台存入数据库后返回ok.(学习IO ...

  8. 了解注解及java提供的几个基本注解

    先通过@SuppreessWarnings的应用让大家直观地了解注解: 通过System.runFinalizersOnExit(true);的编译器警告引出           @SuppressW ...

  9. 注解:java 自定义注解应用实例

    本例子旨在使用自定义注解为实体打上标记,为自动生成 sql 提供依据,模拟 hibernate 的注解,至于注解的原理自己搜吧 1.定义 Table 注解 package test; import j ...

随机推荐

  1. ubuntu中误删/var/lib/dpkg/info的补救方法

    今晚在ubuntu上安装一个软件时,出现这样的错误提示:E: Sub-process /usr/bin/dpkg returned an error code (1)然后在网上找了查找问题原因及解决方 ...

  2. Python 内置的GUI库tkinter方法在py2和py3中的更改

    参考资料:   https://docs.python.org/3.4/library/tkinter.html#tkinter-moduleshttps://docs.python.org/2.7/ ...

  3. ettercap局域网DNS欺骗实现过程

    转载:https://www.cnblogs.com/hkleak/p/5043063.html 笔记一:ettercap是什么? 我们在对WEB安全检测的时候都会用到Cain和netfuke这两款工 ...

  4. python文件引用其他文件中的变量

    问题: 然后再另一个文件中引用该变量 报错:Cannot find reference 'User_Agent' in '__init__.py' less... (Ctrl+F1) 正确写法: fr ...

  5. 转 python3中SQLLIT编码与解码之Unicode与bytes

    #########sample########## sqlite3.OperationalError: Could not decode to UTF-8 column 'logtype' with ...

  6. c++ 封装线程库 1

    1.Pthread条件变量简介 条件变量也是线程间同步一个重要的内容,如果说互斥是一个种竞争关系,那么条件变量用于协调线程之间的关系,是一种合作关系. 条件变量的应用很多,例如:BlockingQue ...

  7. checkbox多选、全选js效果

    //全选checkbox function allCheck() { //全选input var all = $("input[name='all']"); //全部的input ...

  8. javascript 例外处理Try{}catch(e){}

    程序开发中,编程人员经常要面对的是如何编写代码来响应错误事件的发生,即例外处理(exception handlers).如果例外处理代码设计得周全,那么最终呈现给用户的就将是一个友好的界面.否则,就会 ...

  9. 卸载 maya

    AUTO Uninstaller 更新下载地址 1.选择MAYA 2.选择版本 3.点击[开始卸载]

  10. Json JsonUtility对字典/列表的序列化,反序列化

    Unity5.3从开始追加的JsonUtility,但是对于List 和Dictionary不能被直接序列化存储. 例如: 数据模型: using UnityEngine; using System; ...