Swift - 协议(protocol)
来源:互联网 发布:linux中cat命令语法 编辑:程序博客网 时间:2024/04/28 18:32
Swift - 协议(protocol)
1,Swift中协议类似于别的语言里的接口,协议里只做方法的声明,包括方法名、返回值、参数等信息,而没有具体的方法实现。
3,如果某个类集继承了某个父类,又遵循了某个协议,那么冒号后面应该先写父类,再写协议
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
protocol
Person
{
//读写属性
var
name:
String
{
get
set
}
//只读属性
var
age:
Int
{
get
}
//类型方法
static
func
method1()
//实例方法
func
method2() ->
Int
//突变方法
mutating
func
method3()
}
2,协议可以继承另一个协议
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
protocol
Animal
{
func
move()
}
protocol
Bird
:
Animal
{
func
song()
}
class
Chiken
:
Bird
{
func
song(){
print
(
"母鸡咯咯"
)
}
func
move(){
print
(
"母鸡走"
)
}
}
3,如果某个类集继承了某个父类,又遵循了某个协议,那么冒号后面应该先写父类,再写协议
1
2
class
CC
:继承的父类, 协议1, 协议2{
}
原文出自:www.hangge.com 转载请保留原文链接:http://www.hangge.com/blog/cache/detail_526.html
0 0
- Swift协议(Protocol)
- Swift - 协议(protocol)
- Swift - 协议(protocol)
- Swift之协议( protocol)
- Swift学习 协议Protocol
- Swift protocol协议
- Swift 中的协议 (Protocol)
- Swift协议合成(protocol composition)
- 第六节 Swift 协议(Protocol)和扩展(Extension)
- Swift中扩展extension与协议protocol
- [Swift 开发] 协议扩展(protocol Extension)
- Swift的protocol与协议扩展
- Swift 关于protocol 协议 小解 拙见
- swift 关于protocol协议笔记实现
- swift 协议Protocol的基本用法
- 协议(Protocol)
- OC Protocol(协议)
- Protocol(协议)
- 欢迎使用CSDN-markdown编辑器
- Java上传文件common-fileupload
- CSDN第一天
- option参数
- POJ 2763 树链剖分
- Swift - 协议(protocol)
- Linux下常用命令大全
- 欢迎使用CSDN-markdown编辑器
- 注册广播接收者两种方式的区别,及优缺点
- 个人网站搭建—环境配置(ISS、PHP、MySQL)
- Linux内核中读写文件
- UVA - 699 The Falling Leaves 二叉树
- 数据类型以及变量与常量
- Tkinter教程之Message篇