Skip to content

Commit 8c847c0

Browse files
committed
SwiftMysterious
1 parent 559557b commit 8c847c0

5 files changed

Lines changed: 392 additions & 0 deletions

File tree

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 46;
7+
objects = {
8+
9+
/* Begin PBXBuildFile section */
10+
9B71F0681C5B8A020002C59D /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B71F0671C5B8A020002C59D /* main.swift */; };
11+
9B71F06F1C5B8F8E0002C59D /* InlineLazy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B71F06E1C5B8F8E0002C59D /* InlineLazy.swift */; };
12+
9B71F0711C5BA1620002C59D /* SpecialLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B71F0701C5BA1620002C59D /* SpecialLiteral.swift */; };
13+
9B71F0731C5BA38E0002C59D /* LoopLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B71F0721C5BA38E0002C59D /* LoopLabel.swift */; };
14+
/* End PBXBuildFile section */
15+
16+
/* Begin PBXCopyFilesBuildPhase section */
17+
9B71F0621C5B8A020002C59D /* CopyFiles */ = {
18+
isa = PBXCopyFilesBuildPhase;
19+
buildActionMask = 2147483647;
20+
dstPath = /usr/share/man/man1/;
21+
dstSubfolderSpec = 0;
22+
files = (
23+
);
24+
runOnlyForDeploymentPostprocessing = 1;
25+
};
26+
/* End PBXCopyFilesBuildPhase section */
27+
28+
/* Begin PBXFileReference section */
29+
9B71F0641C5B8A020002C59D /* SwiftMysterious */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SwiftMysterious; sourceTree = BUILT_PRODUCTS_DIR; };
30+
9B71F0671C5B8A020002C59D /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
31+
9B71F06E1C5B8F8E0002C59D /* InlineLazy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InlineLazy.swift; sourceTree = "<group>"; };
32+
9B71F0701C5BA1620002C59D /* SpecialLiteral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpecialLiteral.swift; sourceTree = "<group>"; };
33+
9B71F0721C5BA38E0002C59D /* LoopLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoopLabel.swift; sourceTree = "<group>"; };
34+
/* End PBXFileReference section */
35+
36+
/* Begin PBXFrameworksBuildPhase section */
37+
9B71F0611C5B8A020002C59D /* Frameworks */ = {
38+
isa = PBXFrameworksBuildPhase;
39+
buildActionMask = 2147483647;
40+
files = (
41+
);
42+
runOnlyForDeploymentPostprocessing = 0;
43+
};
44+
/* End PBXFrameworksBuildPhase section */
45+
46+
/* Begin PBXGroup section */
47+
9B71F05B1C5B8A020002C59D = {
48+
isa = PBXGroup;
49+
children = (
50+
9B71F0661C5B8A020002C59D /* SwiftMysterious */,
51+
9B71F0651C5B8A020002C59D /* Products */,
52+
);
53+
sourceTree = "<group>";
54+
};
55+
9B71F0651C5B8A020002C59D /* Products */ = {
56+
isa = PBXGroup;
57+
children = (
58+
9B71F0641C5B8A020002C59D /* SwiftMysterious */,
59+
);
60+
name = Products;
61+
sourceTree = "<group>";
62+
};
63+
9B71F0661C5B8A020002C59D /* SwiftMysterious */ = {
64+
isa = PBXGroup;
65+
children = (
66+
9B71F0671C5B8A020002C59D /* main.swift */,
67+
9B71F06E1C5B8F8E0002C59D /* InlineLazy.swift */,
68+
9B71F0701C5BA1620002C59D /* SpecialLiteral.swift */,
69+
9B71F0721C5BA38E0002C59D /* LoopLabel.swift */,
70+
);
71+
path = SwiftMysterious;
72+
sourceTree = "<group>";
73+
};
74+
/* End PBXGroup section */
75+
76+
/* Begin PBXNativeTarget section */
77+
9B71F0631C5B8A020002C59D /* SwiftMysterious */ = {
78+
isa = PBXNativeTarget;
79+
buildConfigurationList = 9B71F06B1C5B8A020002C59D /* Build configuration list for PBXNativeTarget "SwiftMysterious" */;
80+
buildPhases = (
81+
9B71F0601C5B8A020002C59D /* Sources */,
82+
9B71F0611C5B8A020002C59D /* Frameworks */,
83+
9B71F0621C5B8A020002C59D /* CopyFiles */,
84+
);
85+
buildRules = (
86+
);
87+
dependencies = (
88+
);
89+
name = SwiftMysterious;
90+
productName = SwiftMysterious;
91+
productReference = 9B71F0641C5B8A020002C59D /* SwiftMysterious */;
92+
productType = "com.apple.product-type.tool";
93+
};
94+
/* End PBXNativeTarget section */
95+
96+
/* Begin PBXProject section */
97+
9B71F05C1C5B8A020002C59D /* Project object */ = {
98+
isa = PBXProject;
99+
attributes = {
100+
LastSwiftUpdateCheck = 0720;
101+
LastUpgradeCheck = 0720;
102+
ORGANIZATIONNAME = zxy;
103+
TargetAttributes = {
104+
9B71F0631C5B8A020002C59D = {
105+
CreatedOnToolsVersion = 7.2;
106+
};
107+
};
108+
};
109+
buildConfigurationList = 9B71F05F1C5B8A020002C59D /* Build configuration list for PBXProject "SwiftMysterious" */;
110+
compatibilityVersion = "Xcode 3.2";
111+
developmentRegion = English;
112+
hasScannedForEncodings = 0;
113+
knownRegions = (
114+
en,
115+
);
116+
mainGroup = 9B71F05B1C5B8A020002C59D;
117+
productRefGroup = 9B71F0651C5B8A020002C59D /* Products */;
118+
projectDirPath = "";
119+
projectRoot = "";
120+
targets = (
121+
9B71F0631C5B8A020002C59D /* SwiftMysterious */,
122+
);
123+
};
124+
/* End PBXProject section */
125+
126+
/* Begin PBXSourcesBuildPhase section */
127+
9B71F0601C5B8A020002C59D /* Sources */ = {
128+
isa = PBXSourcesBuildPhase;
129+
buildActionMask = 2147483647;
130+
files = (
131+
9B71F0731C5BA38E0002C59D /* LoopLabel.swift in Sources */,
132+
9B71F06F1C5B8F8E0002C59D /* InlineLazy.swift in Sources */,
133+
9B71F0681C5B8A020002C59D /* main.swift in Sources */,
134+
9B71F0711C5BA1620002C59D /* SpecialLiteral.swift in Sources */,
135+
);
136+
runOnlyForDeploymentPostprocessing = 0;
137+
};
138+
/* End PBXSourcesBuildPhase section */
139+
140+
/* Begin XCBuildConfiguration section */
141+
9B71F0691C5B8A020002C59D /* Debug */ = {
142+
isa = XCBuildConfiguration;
143+
buildSettings = {
144+
ALWAYS_SEARCH_USER_PATHS = NO;
145+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
146+
CLANG_CXX_LIBRARY = "libc++";
147+
CLANG_ENABLE_MODULES = YES;
148+
CLANG_ENABLE_OBJC_ARC = YES;
149+
CLANG_WARN_BOOL_CONVERSION = YES;
150+
CLANG_WARN_CONSTANT_CONVERSION = YES;
151+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
152+
CLANG_WARN_EMPTY_BODY = YES;
153+
CLANG_WARN_ENUM_CONVERSION = YES;
154+
CLANG_WARN_INT_CONVERSION = YES;
155+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
156+
CLANG_WARN_UNREACHABLE_CODE = YES;
157+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
158+
CODE_SIGN_IDENTITY = "-";
159+
COPY_PHASE_STRIP = NO;
160+
DEBUG_INFORMATION_FORMAT = dwarf;
161+
ENABLE_STRICT_OBJC_MSGSEND = YES;
162+
ENABLE_TESTABILITY = YES;
163+
GCC_C_LANGUAGE_STANDARD = gnu99;
164+
GCC_DYNAMIC_NO_PIC = NO;
165+
GCC_NO_COMMON_BLOCKS = YES;
166+
GCC_OPTIMIZATION_LEVEL = 0;
167+
GCC_PREPROCESSOR_DEFINITIONS = (
168+
"DEBUG=1",
169+
"$(inherited)",
170+
);
171+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
172+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
173+
GCC_WARN_UNDECLARED_SELECTOR = YES;
174+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
175+
GCC_WARN_UNUSED_FUNCTION = YES;
176+
GCC_WARN_UNUSED_VARIABLE = YES;
177+
MACOSX_DEPLOYMENT_TARGET = 10.11;
178+
MTL_ENABLE_DEBUG_INFO = YES;
179+
ONLY_ACTIVE_ARCH = YES;
180+
SDKROOT = macosx;
181+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
182+
};
183+
name = Debug;
184+
};
185+
9B71F06A1C5B8A020002C59D /* Release */ = {
186+
isa = XCBuildConfiguration;
187+
buildSettings = {
188+
ALWAYS_SEARCH_USER_PATHS = NO;
189+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
190+
CLANG_CXX_LIBRARY = "libc++";
191+
CLANG_ENABLE_MODULES = YES;
192+
CLANG_ENABLE_OBJC_ARC = YES;
193+
CLANG_WARN_BOOL_CONVERSION = YES;
194+
CLANG_WARN_CONSTANT_CONVERSION = YES;
195+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
196+
CLANG_WARN_EMPTY_BODY = YES;
197+
CLANG_WARN_ENUM_CONVERSION = YES;
198+
CLANG_WARN_INT_CONVERSION = YES;
199+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
200+
CLANG_WARN_UNREACHABLE_CODE = YES;
201+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
202+
CODE_SIGN_IDENTITY = "-";
203+
COPY_PHASE_STRIP = NO;
204+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
205+
ENABLE_NS_ASSERTIONS = NO;
206+
ENABLE_STRICT_OBJC_MSGSEND = YES;
207+
GCC_C_LANGUAGE_STANDARD = gnu99;
208+
GCC_NO_COMMON_BLOCKS = YES;
209+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
210+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
211+
GCC_WARN_UNDECLARED_SELECTOR = YES;
212+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
213+
GCC_WARN_UNUSED_FUNCTION = YES;
214+
GCC_WARN_UNUSED_VARIABLE = YES;
215+
MACOSX_DEPLOYMENT_TARGET = 10.11;
216+
MTL_ENABLE_DEBUG_INFO = NO;
217+
SDKROOT = macosx;
218+
};
219+
name = Release;
220+
};
221+
9B71F06C1C5B8A020002C59D /* Debug */ = {
222+
isa = XCBuildConfiguration;
223+
buildSettings = {
224+
PRODUCT_NAME = "$(TARGET_NAME)";
225+
};
226+
name = Debug;
227+
};
228+
9B71F06D1C5B8A020002C59D /* Release */ = {
229+
isa = XCBuildConfiguration;
230+
buildSettings = {
231+
PRODUCT_NAME = "$(TARGET_NAME)";
232+
};
233+
name = Release;
234+
};
235+
/* End XCBuildConfiguration section */
236+
237+
/* Begin XCConfigurationList section */
238+
9B71F05F1C5B8A020002C59D /* Build configuration list for PBXProject "SwiftMysterious" */ = {
239+
isa = XCConfigurationList;
240+
buildConfigurations = (
241+
9B71F0691C5B8A020002C59D /* Debug */,
242+
9B71F06A1C5B8A020002C59D /* Release */,
243+
);
244+
defaultConfigurationIsVisible = 0;
245+
defaultConfigurationName = Release;
246+
};
247+
9B71F06B1C5B8A020002C59D /* Build configuration list for PBXNativeTarget "SwiftMysterious" */ = {
248+
isa = XCConfigurationList;
249+
buildConfigurations = (
250+
9B71F06C1C5B8A020002C59D /* Debug */,
251+
9B71F06D1C5B8A020002C59D /* Release */,
252+
);
253+
defaultConfigurationIsVisible = 0;
254+
};
255+
/* End XCConfigurationList section */
256+
};
257+
rootObject = 9B71F05C1C5B8A020002C59D /* Project object */;
258+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// InlineLazy.swift
3+
// SwiftMysterious
4+
//
5+
// Created by 张星宇 on 16/1/29.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/// Important!!!!
12+
/// 虽然懒加载的本质是闭包,而且闭包中捕获了self,但是这里并不会产生循环引用
13+
/// 猜测Swift在捕获self时,自动把它标记为unowned
14+
15+
class ExpensiveObject {
16+
init () {
17+
print("初始化ExpensiveObject对象的过程非常耗时")
18+
}
19+
}
20+
21+
class PersonOld {
22+
lazy var expensiveObject: ExpensiveObject = {
23+
return self.createExpensiveObject() // 传统实现方式
24+
}()
25+
26+
private func createExpensiveObject() -> ExpensiveObject {
27+
return ExpensiveObject()
28+
}
29+
30+
deinit {
31+
print("Person 对象销毁")
32+
}
33+
}
34+
35+
class Person {
36+
// 内联的lazy属性可以简化不少代码
37+
lazy var expensiveObject: ExpensiveObject = self.createExpensiveObject()
38+
39+
private func createExpensiveObject() -> ExpensiveObject {
40+
return ExpensiveObject()
41+
}
42+
43+
deinit {
44+
print("Person 对象销毁")
45+
}
46+
}
47+
48+
func lazyVariable() {
49+
print("传统的lazy属性的实现")
50+
let p = PersonOld()
51+
_ = p.expensiveObject
52+
}
53+
54+
func inlineLazyVariable() {
55+
print("\n内联lazy属性的实现")
56+
let p = Person()
57+
_ = p.expensiveObject
58+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// LoopLabel.swift
3+
// SwiftMysterious
4+
//
5+
// Created by 张星宇 on 16/1/29.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
let firstNames = ["Neil","Kt","Bob"]
12+
let lastNames = ["Zhou","Zhang","Wang","Li"]
13+
14+
func normalBreak() {
15+
print("\n正常的break循环")
16+
for firstName in firstNames {
17+
var isFound = false
18+
for lastName in lastNames {
19+
if firstName == "Kt" && lastName == "Zhang" {
20+
isFound = true
21+
break
22+
}
23+
print(firstName + " " + lastName)
24+
}
25+
26+
if isFound {
27+
break
28+
}
29+
}
30+
}
31+
32+
func breakWithLoopLabel() {
33+
print("\n使用循环标签的break循环")
34+
outsideloop: for firstName in firstNames {
35+
innerloop: for lastName in lastNames {
36+
if firstName == "Kt" && lastName == "Zhang" {
37+
break outsideloop
38+
}
39+
print(firstName + " " + lastName)
40+
}
41+
}
42+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// SpecialLiteral.swift
3+
// SwiftMysterious
4+
//
5+
// Created by 张星宇 on 16/1/29.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
func specialLitertalExpression() {
12+
print("\n用于调试的特殊字面量表达式")
13+
print(__FILE__)
14+
print(__FUNCTION__)
15+
print(__LINE__)
16+
print(__COLUMN__) // 输出结果为11,因为有4个空格,print是五个字符,还有一个左括号。
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// main.swift
3+
// SwiftMysterious
4+
//
5+
// Created by 张星宇 on 16/1/29.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
lazyVariable() // 默认的lazy属性实现
12+
inlineLazyVariable() // 内联的lazy属性实现
13+
14+
specialLitertalExpression() // 用于调试的特殊字面量表达式
15+
16+
normalBreak() // 正常的break循环
17+
breakWithLoopLabel() // 使用循环标签的break循环

0 commit comments

Comments
 (0)