Skip to content

Commit 07ce8eb

Browse files
committed
添加一些示范代码
1 parent d291c11 commit 07ce8eb

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

Enum/Enum.xcodeproj/project.pbxproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
9BBAB5CF1C44A36A003D6A4B /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BBAB5CE1C44A36A003D6A4B /* main.swift */; };
1111
9BCFBB7E1C44C89300F7ED4B /* Tree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BCFBB7D1C44C89300F7ED4B /* Tree.swift */; };
12+
9BCFBB811C44CF4100F7ED4B /* OCEnum.h in Sources */ = {isa = PBXBuildFile; fileRef = 9BCFBB801C44CF4100F7ED4B /* OCEnum.h */; };
1213
/* End PBXBuildFile section */
1314

1415
/* Begin PBXCopyFilesBuildPhase section */
@@ -27,6 +28,8 @@
2728
9BBAB5CB1C44A36A003D6A4B /* Enum */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Enum; sourceTree = BUILT_PRODUCTS_DIR; };
2829
9BBAB5CE1C44A36A003D6A4B /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
2930
9BCFBB7D1C44C89300F7ED4B /* Tree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tree.swift; sourceTree = "<group>"; };
31+
9BCFBB7F1C44CF4100F7ED4B /* Enum-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Enum-Bridging-Header.h"; sourceTree = "<group>"; };
32+
9BCFBB801C44CF4100F7ED4B /* OCEnum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCEnum.h; sourceTree = "<group>"; };
3033
/* End PBXFileReference section */
3134

3235
/* Begin PBXFrameworksBuildPhase section */
@@ -60,7 +63,9 @@
6063
isa = PBXGroup;
6164
children = (
6265
9BBAB5CE1C44A36A003D6A4B /* main.swift */,
66+
9BCFBB801C44CF4100F7ED4B /* OCEnum.h */,
6367
9BCFBB7D1C44C89300F7ED4B /* Tree.swift */,
68+
9BCFBB7F1C44CF4100F7ED4B /* Enum-Bridging-Header.h */,
6469
);
6570
path = Enum;
6671
sourceTree = "<group>";
@@ -123,6 +128,7 @@
123128
buildActionMask = 2147483647;
124129
files = (
125130
9BBAB5CF1C44A36A003D6A4B /* main.swift in Sources */,
131+
9BCFBB811C44CF4100F7ED4B /* OCEnum.h in Sources */,
126132
9BCFBB7E1C44C89300F7ED4B /* Tree.swift in Sources */,
127133
);
128134
runOnlyForDeploymentPostprocessing = 0;
@@ -213,14 +219,21 @@
213219
9BBAB5D31C44A36A003D6A4B /* Debug */ = {
214220
isa = XCBuildConfiguration;
215221
buildSettings = {
222+
CLANG_ENABLE_MODULES = YES;
223+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
216224
PRODUCT_NAME = "$(TARGET_NAME)";
225+
SWIFT_OBJC_BRIDGING_HEADER = "Enum/Enum-Bridging-Header.h";
226+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
217227
};
218228
name = Debug;
219229
};
220230
9BBAB5D41C44A36A003D6A4B /* Release */ = {
221231
isa = XCBuildConfiguration;
222232
buildSettings = {
233+
CLANG_ENABLE_MODULES = YES;
234+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
223235
PRODUCT_NAME = "$(TARGET_NAME)";
236+
SWIFT_OBJC_BRIDGING_HEADER = "Enum/Enum-Bridging-Header.h";
224237
};
225238
name = Release;
226239
};

Enum/Enum/Enum-Bridging-Header.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//
4+
5+
#import "OCEnum.h"

Enum/Enum/OCEnum.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// OCEnum.m
3+
// Enum
4+
//
5+
// Created by 张星宇 on 16/1/12.
6+
// Copyright © 2016年 张星宇. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
typedef NS_ENUM(NSInteger, MyEnum) {
12+
//以下是枚举成员
13+
ValueA = 1, // 如果不写值,默认为1,这是枚举的原始值
14+
ValueB, // 默认是ValueA的值加1
15+
ValueC, // 默认是ValueB的值加1,以此类推
16+
ValueD
17+
};

Enum/Enum/main.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@
99
/// 测试红黑树的实现
1010
import Foundation
1111

12+
/// OC中的枚举一般是这样用的
13+
var enumValue = MyEnum.ValueA
14+
15+
/// 关联类型的基本使用
16+
enum Password {
17+
case DeigtPassword(Int)
18+
case StringPassword(String)
19+
}
20+
21+
var password = Password.DeigtPassword(123456)
22+
password = .StringPassword("123456")
23+
24+
switch password {
25+
case .DeigtPassword(let digit): print("这是数字密码: \(digit)")
26+
case .StringPassword(let digit): print("这是字符串密码: \(digit)")
27+
}
28+
1229
/// 测试contains方法
1330
let root = Tree(3), x = Tree<Int>()
1431
print(root.contains(3)) // true

0 commit comments

Comments
 (0)