Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Swift基础知识大全; Swift学习从简单到复杂; 不断地完善与更新

基础篇
===
知识架构:
###[点我>>>知识架构:](https://github.com/iOS-Swift-Developers/Swift/tree/master/%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95)

- 常两变量
- 基本数据类型
Expand Down Expand Up @@ -44,10 +44,12 @@ Swift基础知识大全; Swift学习从简单到复杂; 不断地完善与更新
- 泛型
- Swift语法补充
- Swift4.0KVC和KVO
- 闭包补充
- 异常处理

### 今日更新
- Swift语法补充
- Swift4.0KVC和KVO
- 闭包补充
- 异常处理

## 更新中...
接下来开始解读 Swift项目之UIKit和Foundation相关框架!
Expand Down
Binary file not shown.
Binary file not shown.
Binary file added Swift电子图书大全/eBook.pdf
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
47C8B57B1EFA05900008A0D4 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47C8B57A1EFA05900008A0D4 /* main.swift */; };
47CA67D41EF0C30A00A17FAC /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47CA67D31EF0C30A00A17FAC /* main.swift */; };
47CA67EA1EF0DDE700A17FAC /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47CA67E91EF0DDE700A17FAC /* main.swift */; };
47D422991F176F80005DEFF0 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47D422981F176F80005DEFF0 /* main.swift */; };
47F59D861F146116003BA564 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47F59D851F146116003BA564 /* main.swift */; };
47FF0F031EDFF03A00C0ACC1 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FF0F021EDFF03A00C0ACC1 /* main.swift */; };
47FF0F101EDFF0B000C0ACC1 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FF0F0F1EDFF0B000C0ACC1 /* main.swift */; };
Expand Down Expand Up @@ -320,6 +321,15 @@
);
runOnlyForDeploymentPostprocessing = 1;
};
47D422941F176F80005DEFF0 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
47F59D811F146116003BA564 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -473,6 +483,8 @@
47CA67D31EF0C30A00A17FAC /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
47CA67E71EF0DDE700A17FAC /* 构造方法1 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "构造方法1"; sourceTree = BUILT_PRODUCTS_DIR; };
47CA67E91EF0DDE700A17FAC /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
47D422961F176F80005DEFF0 /* 代理模式 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "代理模式"; sourceTree = BUILT_PRODUCTS_DIR; };
47D422981F176F80005DEFF0 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
47F59D831F146116003BA564 /* 泛型 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "泛型"; sourceTree = BUILT_PRODUCTS_DIR; };
47F59D851F146116003BA564 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
47FF0EFF1EDFF03A00C0ACC1 /* Swift基础语法大全 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Swift基础语法大全"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -706,6 +718,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
47D422931F176F80005DEFF0 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
47F59D801F146116003BA564 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1019,6 +1038,14 @@
path = "构造方法1";
sourceTree = "<group>";
};
47D422971F176F80005DEFF0 /* 代理模式 */ = {
isa = PBXGroup;
children = (
47D422981F176F80005DEFF0 /* main.swift */,
);
path = "代理模式";
sourceTree = "<group>";
};
47F59D841F146116003BA564 /* 泛型 */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1070,6 +1097,7 @@
47F59D841F146116003BA564 /* 泛型 */,
47359D451F15A60C0066598D /* Swift语法补充 */,
47359D501F15A63A0066598D /* Swift4.0KVC和KVO */,
47D422971F176F80005DEFF0 /* 代理模式 */,
47FF0F001EDFF03A00C0ACC1 /* Products */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -1117,6 +1145,7 @@
47F59D831F146116003BA564 /* 泛型 */,
47359D441F15A60C0066598D /* Swift语法补充 */,
47359D4F1F15A63A0066598D /* Swift4.0KVC和KVO */,
47D422961F176F80005DEFF0 /* 代理模式 */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -1706,6 +1735,23 @@
productReference = 47CA67E71EF0DDE700A17FAC /* 构造方法1 */;
productType = "com.apple.product-type.tool";
};
47D422951F176F80005DEFF0 /* 代理模式 */ = {
isa = PBXNativeTarget;
buildConfigurationList = 47D4229C1F176F80005DEFF0 /* Build configuration list for PBXNativeTarget "代理模式" */;
buildPhases = (
47D422921F176F80005DEFF0 /* Sources */,
47D422931F176F80005DEFF0 /* Frameworks */,
47D422941F176F80005DEFF0 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = "代理模式";
productName = "代理模式";
productReference = 47D422961F176F80005DEFF0 /* 代理模式 */;
productType = "com.apple.product-type.tool";
};
47F59D821F146116003BA564 /* 泛型 */ = {
isa = PBXNativeTarget;
buildConfigurationList = 47F59D891F146116003BA564 /* Build configuration list for PBXNativeTarget "泛型" */;
Expand Down Expand Up @@ -2036,6 +2082,11 @@
DevelopmentTeam = WTB2BKP7UZ;
ProvisioningStyle = Automatic;
};
47D422951F176F80005DEFF0 = {
CreatedOnToolsVersion = 8.3.3;
DevelopmentTeam = WTB2BKP7UZ;
ProvisioningStyle = Automatic;
};
47F59D821F146116003BA564 = {
CreatedOnToolsVersion = 8.3.3;
DevelopmentTeam = WTB2BKP7UZ;
Expand Down Expand Up @@ -2140,6 +2191,7 @@
47F59D821F146116003BA564 /* 泛型 */,
47359D431F15A60C0066598D /* Swift语法补充 */,
47359D4E1F15A63A0066598D /* Swift4.0KVC和KVO */,
47D422951F176F80005DEFF0 /* 代理模式 */,
);
};
/* End PBXProject section */
Expand Down Expand Up @@ -2385,6 +2437,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
47D422921F176F80005DEFF0 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
47D422991F176F80005DEFF0 /* main.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
47F59D7F1F146116003BA564 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -3008,6 +3068,24 @@
};
name = Release;
};
47D4229A1F176F80005DEFF0 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEVELOPMENT_TEAM = WTB2BKP7UZ;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
47D4229B1F176F80005DEFF0 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEVELOPMENT_TEAM = WTB2BKP7UZ;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
47F59D871F146116003BA564 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -3315,6 +3393,7 @@
47359D491F15A60C0066598D /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
47359D531F15A63A0066598D /* Build configuration list for PBXNativeTarget "Swift4.0KVC和KVO" */ = {
isa = XCConfigurationList;
Expand All @@ -3323,6 +3402,7 @@
47359D551F15A63A0066598D /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
47370BDB1EEE7C6800C6617B /* Build configuration list for PBXNativeTarget "属性" */ = {
isa = XCConfigurationList;
Expand Down Expand Up @@ -3549,6 +3629,14 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
47D4229C1F176F80005DEFF0 /* Build configuration list for PBXNativeTarget "代理模式" */ = {
isa = XCConfigurationList;
buildConfigurations = (
47D4229A1F176F80005DEFF0 /* Debug */,
47D4229B1F176F80005DEFF0 /* Release */,
);
defaultConfigurationIsVisible = 0;
};
47F59D891F146116003BA564 /* Build configuration list for PBXNativeTarget "泛型" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 23 additions & 1 deletion for/main.swift → 基础语法/for/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,31 @@ for i in 0...10 {
print(rs)


/* --- 2017.07.12 更新 */
/* 0 ~ 50 的遍历 跨步 10
此种方法相当于遍历开区间 0..<50, [0,50) 不会遍历最后一个数
用法常见对数组的遍历,可防止数组取值越界
*/
for i in stride(from: 0, to: 50, by: 10) {
print("i = \(i)")
}

/* 0 ~ 20 的遍历 跨步 5
此种方法相当于遍历 0..<50 [0,50] 闭区间 会遍历最后一个数
*/
for j in stride(from: 0, through: 20, by: 5) {
print("j = \(j)")
}


/*
遍历元组 (实际跟遍历字典类似)
*/
let tupleArray = [("zhangShang",60,170.0),
("liSi",77,175.0),
("wangWu",80,180.0)]
for t in tupleArray {
print("name : \(t.0), weight : \(t.1), height : \(t.2)")
}



Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
75 changes: 75 additions & 0 deletions 基础语法/代理模式/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// main.swift
// 代理模式
//
// Created by 韩俊强 on 2017/7/13.
// Copyright © 2017年 HaRi. All rights reserved.
//

import Foundation

/*
Swfit3.0中代理的使用方法:
*/

//// 一.视图界面中

// 1.制订协议(不谢NSObjectProtocol暂时不会报错, 但是写属性是无法写weak)
protocol DelegateName : NSObjectProtocol {
//设置协议方法
func method()
}
//在Swift中,制定协议需要遵守NSObjectProtocol协议, 除了类可以遵守协议, 结构体也可以遵守协议;

//在OC中我们制定协议, 通常继承自NSObject, 可以这样理解,所有继承自NSObject的对象都可以实现协议方法(同样我们也可以指定哪些对象可以实现我们制定的协议方法);

// 2.用weak定义代理
weak var delegate1 : DelegateName?

// 3.判断代理是否存在, 让代理去执行方法
func clickButton() {
//"?"替代了responsed
delegate1?.method()
}

//// 二.在控制器界面

/*! 由于在main函数里无法运行, 所以暂且注释;
class ViewController : UIViewController, DelegateName { // 1.遵守协议
// 2.设置代理为self
customView?.delegate1 = self

// 3.实现协议方法
func method(){
print("实现协议方法")
}
}
*/



// MARK: 例子: 购票

protocol BuyTicketDelegate : class {
func buyTicket()
}

class Person {
weak var delegate : BuyTicketDelegate?

func goToShanghai(){
delegate?.buyTicket()
}
}

class YellowCattle : BuyTicketDelegate {
func buyTicket() {
print("黄牛党帮你买了一张站票")
}
}

let yellowCattle = YellowCattle()
let person = Person()
person.delegate = yellowCattle
person.goToShanghai()

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion 扩展/main.swift → 基础语法/扩展/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var myTra2 = Transport(scope: "轮船") //使用原构造器, 价格属性的值

/// 3.扩展方法

//扩展证书类型
//扩展整数类型
extension Int {
func calculate() -> Int {
return self * 2
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading