Skip to content

Commit f2d178f

Browse files
committed
Swift小tip
1 parent c0f87e3 commit f2d178f

7 files changed

Lines changed: 382 additions & 0 deletions

File tree

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 46;
7+
objects = {
8+
9+
/* Begin PBXBuildFile section */
10+
9BE365691C60CFCE00C61A55 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BE365681C60CFCE00C61A55 /* main.swift */; };
11+
9BE365741C60D07B00C61A55 /* Closure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BE3656F1C60D07B00C61A55 /* Closure.swift */; };
12+
9BE365751C60D07B00C61A55 /* PrivateSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BE365701C60D07B00C61A55 /* PrivateSet.swift */; };
13+
9BE365761C60D07B00C61A55 /* Semicolon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BE365711C60D07B00C61A55 /* Semicolon.swift */; };
14+
9BE365771C60D07B00C61A55 /* Breakpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BE365721C60D07B00C61A55 /* Breakpoint.swift */; };
15+
9BE365781C60D07B00C61A55 /* ReuseIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BE365731C60D07B00C61A55 /* ReuseIdentifier.swift */; };
16+
/* End PBXBuildFile section */
17+
18+
/* Begin PBXCopyFilesBuildPhase section */
19+
9BE365631C60CFCE00C61A55 /* CopyFiles */ = {
20+
isa = PBXCopyFilesBuildPhase;
21+
buildActionMask = 2147483647;
22+
dstPath = /usr/share/man/man1/;
23+
dstSubfolderSpec = 0;
24+
files = (
25+
);
26+
runOnlyForDeploymentPostprocessing = 1;
27+
};
28+
/* End PBXCopyFilesBuildPhase section */
29+
30+
/* Begin PBXFileReference section */
31+
9BE365651C60CFCE00C61A55 /* SwiftTips */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SwiftTips; sourceTree = BUILT_PRODUCTS_DIR; };
32+
9BE365681C60CFCE00C61A55 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
33+
9BE3656F1C60D07B00C61A55 /* Closure.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Closure.swift; sourceTree = "<group>"; };
34+
9BE365701C60D07B00C61A55 /* PrivateSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrivateSet.swift; sourceTree = "<group>"; };
35+
9BE365711C60D07B00C61A55 /* Semicolon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Semicolon.swift; sourceTree = "<group>"; };
36+
9BE365721C60D07B00C61A55 /* Breakpoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Breakpoint.swift; sourceTree = "<group>"; };
37+
9BE365731C60D07B00C61A55 /* ReuseIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReuseIdentifier.swift; sourceTree = "<group>"; };
38+
/* End PBXFileReference section */
39+
40+
/* Begin PBXFrameworksBuildPhase section */
41+
9BE365621C60CFCE00C61A55 /* Frameworks */ = {
42+
isa = PBXFrameworksBuildPhase;
43+
buildActionMask = 2147483647;
44+
files = (
45+
);
46+
runOnlyForDeploymentPostprocessing = 0;
47+
};
48+
/* End PBXFrameworksBuildPhase section */
49+
50+
/* Begin PBXGroup section */
51+
9BE3655C1C60CFCE00C61A55 = {
52+
isa = PBXGroup;
53+
children = (
54+
9BE365671C60CFCE00C61A55 /* SwiftTips */,
55+
9BE365661C60CFCE00C61A55 /* Products */,
56+
);
57+
sourceTree = "<group>";
58+
};
59+
9BE365661C60CFCE00C61A55 /* Products */ = {
60+
isa = PBXGroup;
61+
children = (
62+
9BE365651C60CFCE00C61A55 /* SwiftTips */,
63+
);
64+
name = Products;
65+
sourceTree = "<group>";
66+
};
67+
9BE365671C60CFCE00C61A55 /* SwiftTips */ = {
68+
isa = PBXGroup;
69+
children = (
70+
9BE365681C60CFCE00C61A55 /* main.swift */,
71+
9BE3656F1C60D07B00C61A55 /* Closure.swift */,
72+
9BE365701C60D07B00C61A55 /* PrivateSet.swift */,
73+
9BE365711C60D07B00C61A55 /* Semicolon.swift */,
74+
9BE365721C60D07B00C61A55 /* Breakpoint.swift */,
75+
9BE365731C60D07B00C61A55 /* ReuseIdentifier.swift */,
76+
);
77+
path = SwiftTips;
78+
sourceTree = "<group>";
79+
};
80+
/* End PBXGroup section */
81+
82+
/* Begin PBXNativeTarget section */
83+
9BE365641C60CFCE00C61A55 /* SwiftTips */ = {
84+
isa = PBXNativeTarget;
85+
buildConfigurationList = 9BE3656C1C60CFCE00C61A55 /* Build configuration list for PBXNativeTarget "SwiftTips" */;
86+
buildPhases = (
87+
9BE365611C60CFCE00C61A55 /* Sources */,
88+
9BE365621C60CFCE00C61A55 /* Frameworks */,
89+
9BE365631C60CFCE00C61A55 /* CopyFiles */,
90+
);
91+
buildRules = (
92+
);
93+
dependencies = (
94+
);
95+
name = SwiftTips;
96+
productName = SwiftTips;
97+
productReference = 9BE365651C60CFCE00C61A55 /* SwiftTips */;
98+
productType = "com.apple.product-type.tool";
99+
};
100+
/* End PBXNativeTarget section */
101+
102+
/* Begin PBXProject section */
103+
9BE3655D1C60CFCE00C61A55 /* Project object */ = {
104+
isa = PBXProject;
105+
attributes = {
106+
LastSwiftUpdateCheck = 0720;
107+
LastUpgradeCheck = 0720;
108+
ORGANIZATIONNAME = zxy;
109+
TargetAttributes = {
110+
9BE365641C60CFCE00C61A55 = {
111+
CreatedOnToolsVersion = 7.2;
112+
};
113+
};
114+
};
115+
buildConfigurationList = 9BE365601C60CFCE00C61A55 /* Build configuration list for PBXProject "SwiftTips" */;
116+
compatibilityVersion = "Xcode 3.2";
117+
developmentRegion = English;
118+
hasScannedForEncodings = 0;
119+
knownRegions = (
120+
en,
121+
);
122+
mainGroup = 9BE3655C1C60CFCE00C61A55;
123+
productRefGroup = 9BE365661C60CFCE00C61A55 /* Products */;
124+
projectDirPath = "";
125+
projectRoot = "";
126+
targets = (
127+
9BE365641C60CFCE00C61A55 /* SwiftTips */,
128+
);
129+
};
130+
/* End PBXProject section */
131+
132+
/* Begin PBXSourcesBuildPhase section */
133+
9BE365611C60CFCE00C61A55 /* Sources */ = {
134+
isa = PBXSourcesBuildPhase;
135+
buildActionMask = 2147483647;
136+
files = (
137+
9BE365691C60CFCE00C61A55 /* main.swift in Sources */,
138+
9BE365781C60D07B00C61A55 /* ReuseIdentifier.swift in Sources */,
139+
9BE365751C60D07B00C61A55 /* PrivateSet.swift in Sources */,
140+
9BE365741C60D07B00C61A55 /* Closure.swift in Sources */,
141+
9BE365771C60D07B00C61A55 /* Breakpoint.swift in Sources */,
142+
9BE365761C60D07B00C61A55 /* Semicolon.swift in Sources */,
143+
);
144+
runOnlyForDeploymentPostprocessing = 0;
145+
};
146+
/* End PBXSourcesBuildPhase section */
147+
148+
/* Begin XCBuildConfiguration section */
149+
9BE3656A1C60CFCE00C61A55 /* Debug */ = {
150+
isa = XCBuildConfiguration;
151+
buildSettings = {
152+
ALWAYS_SEARCH_USER_PATHS = NO;
153+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
154+
CLANG_CXX_LIBRARY = "libc++";
155+
CLANG_ENABLE_MODULES = YES;
156+
CLANG_ENABLE_OBJC_ARC = YES;
157+
CLANG_WARN_BOOL_CONVERSION = YES;
158+
CLANG_WARN_CONSTANT_CONVERSION = YES;
159+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
160+
CLANG_WARN_EMPTY_BODY = YES;
161+
CLANG_WARN_ENUM_CONVERSION = YES;
162+
CLANG_WARN_INT_CONVERSION = YES;
163+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
164+
CLANG_WARN_UNREACHABLE_CODE = YES;
165+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
166+
CODE_SIGN_IDENTITY = "-";
167+
COPY_PHASE_STRIP = NO;
168+
DEBUG_INFORMATION_FORMAT = dwarf;
169+
ENABLE_STRICT_OBJC_MSGSEND = YES;
170+
ENABLE_TESTABILITY = YES;
171+
GCC_C_LANGUAGE_STANDARD = gnu99;
172+
GCC_DYNAMIC_NO_PIC = NO;
173+
GCC_NO_COMMON_BLOCKS = YES;
174+
GCC_OPTIMIZATION_LEVEL = 0;
175+
GCC_PREPROCESSOR_DEFINITIONS = (
176+
"DEBUG=1",
177+
"$(inherited)",
178+
);
179+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
180+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
181+
GCC_WARN_UNDECLARED_SELECTOR = YES;
182+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
183+
GCC_WARN_UNUSED_FUNCTION = YES;
184+
GCC_WARN_UNUSED_VARIABLE = YES;
185+
MACOSX_DEPLOYMENT_TARGET = 10.11;
186+
MTL_ENABLE_DEBUG_INFO = YES;
187+
ONLY_ACTIVE_ARCH = YES;
188+
SDKROOT = macosx;
189+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
190+
};
191+
name = Debug;
192+
};
193+
9BE3656B1C60CFCE00C61A55 /* Release */ = {
194+
isa = XCBuildConfiguration;
195+
buildSettings = {
196+
ALWAYS_SEARCH_USER_PATHS = NO;
197+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
198+
CLANG_CXX_LIBRARY = "libc++";
199+
CLANG_ENABLE_MODULES = YES;
200+
CLANG_ENABLE_OBJC_ARC = YES;
201+
CLANG_WARN_BOOL_CONVERSION = YES;
202+
CLANG_WARN_CONSTANT_CONVERSION = YES;
203+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
204+
CLANG_WARN_EMPTY_BODY = YES;
205+
CLANG_WARN_ENUM_CONVERSION = YES;
206+
CLANG_WARN_INT_CONVERSION = YES;
207+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
208+
CLANG_WARN_UNREACHABLE_CODE = YES;
209+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
210+
CODE_SIGN_IDENTITY = "-";
211+
COPY_PHASE_STRIP = NO;
212+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
213+
ENABLE_NS_ASSERTIONS = NO;
214+
ENABLE_STRICT_OBJC_MSGSEND = YES;
215+
GCC_C_LANGUAGE_STANDARD = gnu99;
216+
GCC_NO_COMMON_BLOCKS = YES;
217+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
218+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
219+
GCC_WARN_UNDECLARED_SELECTOR = YES;
220+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
221+
GCC_WARN_UNUSED_FUNCTION = YES;
222+
GCC_WARN_UNUSED_VARIABLE = YES;
223+
MACOSX_DEPLOYMENT_TARGET = 10.11;
224+
MTL_ENABLE_DEBUG_INFO = NO;
225+
SDKROOT = macosx;
226+
};
227+
name = Release;
228+
};
229+
9BE3656D1C60CFCE00C61A55 /* Debug */ = {
230+
isa = XCBuildConfiguration;
231+
buildSettings = {
232+
PRODUCT_NAME = "$(TARGET_NAME)";
233+
};
234+
name = Debug;
235+
};
236+
9BE3656E1C60CFCE00C61A55 /* Release */ = {
237+
isa = XCBuildConfiguration;
238+
buildSettings = {
239+
PRODUCT_NAME = "$(TARGET_NAME)";
240+
};
241+
name = Release;
242+
};
243+
/* End XCBuildConfiguration section */
244+
245+
/* Begin XCConfigurationList section */
246+
9BE365601C60CFCE00C61A55 /* Build configuration list for PBXProject "SwiftTips" */ = {
247+
isa = XCConfigurationList;
248+
buildConfigurations = (
249+
9BE3656A1C60CFCE00C61A55 /* Debug */,
250+
9BE3656B1C60CFCE00C61A55 /* Release */,
251+
);
252+
defaultConfigurationIsVisible = 0;
253+
defaultConfigurationName = Release;
254+
};
255+
9BE3656C1C60CFCE00C61A55 /* Build configuration list for PBXNativeTarget "SwiftTips" */ = {
256+
isa = XCConfigurationList;
257+
buildConfigurations = (
258+
9BE3656D1C60CFCE00C61A55 /* Debug */,
259+
9BE3656E1C60CFCE00C61A55 /* Release */,
260+
);
261+
defaultConfigurationIsVisible = 0;
262+
};
263+
/* End XCConfigurationList section */
264+
};
265+
rootObject = 9BE3655D1C60CFCE00C61A55 /* Project object */;
266+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Debug.swift
3+
// Handy
4+
//
5+
// Created by 张星宇 on 16/2/2.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
func customDebug() {
12+
for i in 1..<10 {
13+
14+
}
15+
}

SwiftTips/SwiftTips/Closure.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Closure.swift
3+
// Handy
4+
//
5+
// Created by 张星宇 on 16/2/2.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import Cocoa
11+
12+
enum Theme {
13+
case Day, Night, Dusk, Dawn
14+
15+
func applyColor() {
16+
let backgroundColor: NSColor = {
17+
switch self {
18+
case Day: return NSColor.whiteColor()
19+
case Night: return NSColor.darkGrayColor()
20+
default: return NSColor.blackColor()
21+
}
22+
}()
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// PrivateSet.swift
3+
// Handy
4+
//
5+
// Created by 张星宇 on 16/2/2.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
struct Person {
12+
private(set) var name = "Unknown"
13+
}
14+
15+
extension Person {
16+
mutating func changeName(newName: String) {
17+
self.name = newName
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ReuseIdentifier.swift
3+
// Handy
4+
//
5+
// Created by 张星宇 on 16/2/2.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
class TableViewCell {
12+
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Semicolon.swift
3+
// Handy
4+
//
5+
// Created by 张星宇 on 16/2/2.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
func doSomething() {
12+
let error: AnyObject? = nil
13+
guard error == nil else { print("Error information"); return }
14+
}

SwiftTips/SwiftTips/main.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// main.swift
3+
// SwiftTips
4+
//
5+
// Created by 张星宇 on 16/2/2.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
var person = Person()
12+
person.changeName("kt")
13+
14+
// 可以获取name属性的值
15+
print(person.name)
16+
17+
// 报错,不能在PrivateSet.swift文件外对name属性赋值
18+
//person.name = "newName"
19+
20+
/// 可以简化reuseIdentifier
21+
let reuseIdentifier = String(TableViewCell)
22+
print(reuseIdentifier)
23+
24+
// 可以把多个相关联的变量声明在一个元组中
25+
var (top, left, width, height) = (0.0, 0.0, 100.0, 50.0)
26+
//rect.width = width
27+
28+
/**
29+
* 自定义断点
30+
*/
31+
customDebug()

0 commit comments

Comments
 (0)