swift --2
来源:互联网 发布:加盟农村淘宝要多少钱 编辑:程序博客网 时间:2024/06/11 03:08
在swift 中 ? 可选的,可以不赋初始值
! 必须赋初始值
static 可修饰类 但不可以重写
class 可修饰 可重写
class Person{
class func test2(){
print("二师弟正在吃")
}
class Student:Person{
//重写父类方法要有 override
override class func test2(){
print("大师兄,二师兄");
}
// () 相当于alloc init
//协议 protocol关键字 这样写默认是协议必须实现
protocol MyProtocol{
func sayHello()
}
//这种写法 加上@objc 这种写法修饰的协议里面的方法加上optional就可以变成可选择性实现的协议方法 可选择实现的
@objc protocol YourPrptocol{
optional func sayHi()
}
//重写init方法并且写几种init方法,就有几种初始化方式
init(name : String,age : Int){
self.name = name
self.age = age
}
init(name :String){
self.name = name
}
init(){
}
}
class Teacher : MyProtocol{
func sayHello(){
print("hello")
}
//如果我们实现了可选协议方法,那么必须要在func前加上@objc或者让这类继承NSObject,这样就不会报黄色警报
func sayHi(){
print("i like i like")
}
}
// extension 给类拓展协议 ,拓展方法//cell 注册
self tableView registerClass MyTableViewCell classForCoder(),forCellReuseIdentifier:"cell_id"
// 重用
let cell :MyTableViewCell = tableView.dequeReusableCellWithIdentifier("cell_id",forIndexPath:indexPath)as!MyTableViewCell
//属性传值
let VC : LoginViewController = LoginViewController()
self.showViewController(VC, sender: nil);
//pop
self.navigationController?.popToRootViewControllerAnimated(true);
self.myBlock(str:"哈哈哈")
var myBlock : block!
self.myBlock(str:"哈哈哈")
// block 传带参要带in
VC.myBlock = {
a in
print(a)
}
- swift 2
- swift(2)
- Swift 2
- swift-2
- swift --2
- Swift 2
- swift 2
- Swift源码分析----swift-proxy与swift-account(2)
- Swift源码分析----swift-proxy与swift-object(2)
- [openstack swift]1 swift安装(2)
- Swift源码分析----swift-account-audit(2)
- Swift源码分析----swift-object-auditor(2)
- Swift源码分析----swift-account-reaper(2)
- Swift源码分析----swift-account-replicator(2)
- Swift源码分析----swift-object-replicator(2)
- [openstack swift]2基本概念
- [openstack swift]2基本概念
- swift笔记(2)
- implements Serializable有什么作用?
- oracle 安装出现文件找不到的错误
- Innodb的事务处理autocommit参数问题
- java通过DOM操作xml
- 就用这句话激励自己吧
- swift --2
- 使用 tcpdump监听某一端口数据
- MySql错误处理- 错误代码和消息
- Java IO系列0 InputStream与OutputStream(字节流)
- Android学习(3)---Fragment的学习
- C#开启SQLSERVER数据库缓存依赖优化网站性能
- Visual C++6.0 程序设计从入门到精通(三) - MFC的消息机制
- php地址引用
- 开源XListview 的代码分析及使用