Skip to content

Commit 19bae8c

Browse files
iterator、singleton模式
1 parent 708e389 commit 19bae8c

File tree

18 files changed

+985
-0
lines changed

18 files changed

+985
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 迭代器模式
2+
3+
## 什么是迭代器模式?
4+
提供一种方法顺序访问一个聚合对象中各个元素,而又不暴露该对象的内部表示
5+
6+
## 迭代器模式有哪些优点?
7+
8+
## 迭代器模式有哪些缺点?
9+
10+
## 适用场景
11+
* 一个聚集对象, 且不管这些对象是什么,都需要遍历的时候
12+
13+
14+
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 50;
7+
objects = {
8+
9+
/* Begin PBXBuildFile section */
10+
DA36488221D652250091DDB2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DA36488121D652250091DDB2 /* main.m */; };
11+
DA36488B21D652400091DDB2 /* ConcreteIterator.m in Sources */ = {isa = PBXBuildFile; fileRef = DA36488A21D652400091DDB2 /* ConcreteIterator.m */; };
12+
DA36489021D6535E0091DDB2 /* ConcreteAggregate.m in Sources */ = {isa = PBXBuildFile; fileRef = DA36488F21D6535E0091DDB2 /* ConcreteAggregate.m */; };
13+
/* End PBXBuildFile section */
14+
15+
/* Begin PBXCopyFilesBuildPhase section */
16+
DA36487C21D652250091DDB2 /* CopyFiles */ = {
17+
isa = PBXCopyFilesBuildPhase;
18+
buildActionMask = 2147483647;
19+
dstPath = /usr/share/man/man1/;
20+
dstSubfolderSpec = 0;
21+
files = (
22+
);
23+
runOnlyForDeploymentPostprocessing = 1;
24+
};
25+
/* End PBXCopyFilesBuildPhase section */
26+
27+
/* Begin PBXFileReference section */
28+
DA36487E21D652250091DDB2 /* iterator */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = iterator; sourceTree = BUILT_PRODUCTS_DIR; };
29+
DA36488121D652250091DDB2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
30+
DA36488921D652400091DDB2 /* ConcreteIterator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ConcreteIterator.h; sourceTree = "<group>"; };
31+
DA36488A21D652400091DDB2 /* ConcreteIterator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ConcreteIterator.m; sourceTree = "<group>"; };
32+
DA36488C21D6526C0091DDB2 /* Iterator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Iterator.h; sourceTree = "<group>"; };
33+
DA36488D21D652E80091DDB2 /* Aggreagate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Aggreagate.h; sourceTree = "<group>"; };
34+
DA36488E21D6535E0091DDB2 /* ConcreteAggregate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ConcreteAggregate.h; sourceTree = "<group>"; };
35+
DA36488F21D6535E0091DDB2 /* ConcreteAggregate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ConcreteAggregate.m; sourceTree = "<group>"; };
36+
/* End PBXFileReference section */
37+
38+
/* Begin PBXFrameworksBuildPhase section */
39+
DA36487B21D652250091DDB2 /* Frameworks */ = {
40+
isa = PBXFrameworksBuildPhase;
41+
buildActionMask = 2147483647;
42+
files = (
43+
);
44+
runOnlyForDeploymentPostprocessing = 0;
45+
};
46+
/* End PBXFrameworksBuildPhase section */
47+
48+
/* Begin PBXGroup section */
49+
DA36487521D652250091DDB2 = {
50+
isa = PBXGroup;
51+
children = (
52+
DA36488021D652250091DDB2 /* iterator */,
53+
DA36487F21D652250091DDB2 /* Products */,
54+
);
55+
sourceTree = "<group>";
56+
};
57+
DA36487F21D652250091DDB2 /* Products */ = {
58+
isa = PBXGroup;
59+
children = (
60+
DA36487E21D652250091DDB2 /* iterator */,
61+
);
62+
name = Products;
63+
sourceTree = "<group>";
64+
};
65+
DA36488021D652250091DDB2 /* iterator */ = {
66+
isa = PBXGroup;
67+
children = (
68+
DA36488821D652360091DDB2 /* iterator */,
69+
DA36488121D652250091DDB2 /* main.m */,
70+
);
71+
path = iterator;
72+
sourceTree = "<group>";
73+
};
74+
DA36488821D652360091DDB2 /* iterator */ = {
75+
isa = PBXGroup;
76+
children = (
77+
DA36488C21D6526C0091DDB2 /* Iterator.h */,
78+
DA36488921D652400091DDB2 /* ConcreteIterator.h */,
79+
DA36488A21D652400091DDB2 /* ConcreteIterator.m */,
80+
DA36488D21D652E80091DDB2 /* Aggreagate.h */,
81+
DA36488E21D6535E0091DDB2 /* ConcreteAggregate.h */,
82+
DA36488F21D6535E0091DDB2 /* ConcreteAggregate.m */,
83+
);
84+
path = iterator;
85+
sourceTree = "<group>";
86+
};
87+
/* End PBXGroup section */
88+
89+
/* Begin PBXNativeTarget section */
90+
DA36487D21D652250091DDB2 /* iterator */ = {
91+
isa = PBXNativeTarget;
92+
buildConfigurationList = DA36488521D652250091DDB2 /* Build configuration list for PBXNativeTarget "iterator" */;
93+
buildPhases = (
94+
DA36487A21D652250091DDB2 /* Sources */,
95+
DA36487B21D652250091DDB2 /* Frameworks */,
96+
DA36487C21D652250091DDB2 /* CopyFiles */,
97+
);
98+
buildRules = (
99+
);
100+
dependencies = (
101+
);
102+
name = iterator;
103+
productName = iterator;
104+
productReference = DA36487E21D652250091DDB2 /* iterator */;
105+
productType = "com.apple.product-type.tool";
106+
};
107+
/* End PBXNativeTarget section */
108+
109+
/* Begin PBXProject section */
110+
DA36487621D652250091DDB2 /* Project object */ = {
111+
isa = PBXProject;
112+
attributes = {
113+
LastUpgradeCheck = 1010;
114+
ORGANIZATIONNAME = "王俊";
115+
TargetAttributes = {
116+
DA36487D21D652250091DDB2 = {
117+
CreatedOnToolsVersion = 10.1;
118+
};
119+
};
120+
};
121+
buildConfigurationList = DA36487921D652250091DDB2 /* Build configuration list for PBXProject "iterator" */;
122+
compatibilityVersion = "Xcode 9.3";
123+
developmentRegion = en;
124+
hasScannedForEncodings = 0;
125+
knownRegions = (
126+
en,
127+
);
128+
mainGroup = DA36487521D652250091DDB2;
129+
productRefGroup = DA36487F21D652250091DDB2 /* Products */;
130+
projectDirPath = "";
131+
projectRoot = "";
132+
targets = (
133+
DA36487D21D652250091DDB2 /* iterator */,
134+
);
135+
};
136+
/* End PBXProject section */
137+
138+
/* Begin PBXSourcesBuildPhase section */
139+
DA36487A21D652250091DDB2 /* Sources */ = {
140+
isa = PBXSourcesBuildPhase;
141+
buildActionMask = 2147483647;
142+
files = (
143+
DA36489021D6535E0091DDB2 /* ConcreteAggregate.m in Sources */,
144+
DA36488221D652250091DDB2 /* main.m in Sources */,
145+
DA36488B21D652400091DDB2 /* ConcreteIterator.m in Sources */,
146+
);
147+
runOnlyForDeploymentPostprocessing = 0;
148+
};
149+
/* End PBXSourcesBuildPhase section */
150+
151+
/* Begin XCBuildConfiguration section */
152+
DA36488321D652250091DDB2 /* Debug */ = {
153+
isa = XCBuildConfiguration;
154+
buildSettings = {
155+
ALWAYS_SEARCH_USER_PATHS = NO;
156+
CLANG_ANALYZER_NONNULL = YES;
157+
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
158+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
159+
CLANG_CXX_LIBRARY = "libc++";
160+
CLANG_ENABLE_MODULES = YES;
161+
CLANG_ENABLE_OBJC_ARC = YES;
162+
CLANG_ENABLE_OBJC_WEAK = YES;
163+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
164+
CLANG_WARN_BOOL_CONVERSION = YES;
165+
CLANG_WARN_COMMA = YES;
166+
CLANG_WARN_CONSTANT_CONVERSION = YES;
167+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
168+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
169+
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
170+
CLANG_WARN_EMPTY_BODY = YES;
171+
CLANG_WARN_ENUM_CONVERSION = YES;
172+
CLANG_WARN_INFINITE_RECURSION = YES;
173+
CLANG_WARN_INT_CONVERSION = YES;
174+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
175+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
176+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
177+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
178+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
179+
CLANG_WARN_STRICT_PROTOTYPES = YES;
180+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
181+
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
182+
CLANG_WARN_UNREACHABLE_CODE = YES;
183+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
184+
CODE_SIGN_IDENTITY = "Mac Developer";
185+
COPY_PHASE_STRIP = NO;
186+
DEBUG_INFORMATION_FORMAT = dwarf;
187+
ENABLE_STRICT_OBJC_MSGSEND = YES;
188+
ENABLE_TESTABILITY = YES;
189+
GCC_C_LANGUAGE_STANDARD = gnu11;
190+
GCC_DYNAMIC_NO_PIC = NO;
191+
GCC_NO_COMMON_BLOCKS = YES;
192+
GCC_OPTIMIZATION_LEVEL = 0;
193+
GCC_PREPROCESSOR_DEFINITIONS = (
194+
"DEBUG=1",
195+
"$(inherited)",
196+
);
197+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
198+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
199+
GCC_WARN_UNDECLARED_SELECTOR = YES;
200+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
201+
GCC_WARN_UNUSED_FUNCTION = YES;
202+
GCC_WARN_UNUSED_VARIABLE = YES;
203+
MACOSX_DEPLOYMENT_TARGET = 10.14;
204+
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
205+
MTL_FAST_MATH = YES;
206+
ONLY_ACTIVE_ARCH = YES;
207+
SDKROOT = macosx;
208+
};
209+
name = Debug;
210+
};
211+
DA36488421D652250091DDB2 /* Release */ = {
212+
isa = XCBuildConfiguration;
213+
buildSettings = {
214+
ALWAYS_SEARCH_USER_PATHS = NO;
215+
CLANG_ANALYZER_NONNULL = YES;
216+
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
217+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
218+
CLANG_CXX_LIBRARY = "libc++";
219+
CLANG_ENABLE_MODULES = YES;
220+
CLANG_ENABLE_OBJC_ARC = YES;
221+
CLANG_ENABLE_OBJC_WEAK = YES;
222+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
223+
CLANG_WARN_BOOL_CONVERSION = YES;
224+
CLANG_WARN_COMMA = YES;
225+
CLANG_WARN_CONSTANT_CONVERSION = YES;
226+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
227+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
228+
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
229+
CLANG_WARN_EMPTY_BODY = YES;
230+
CLANG_WARN_ENUM_CONVERSION = YES;
231+
CLANG_WARN_INFINITE_RECURSION = YES;
232+
CLANG_WARN_INT_CONVERSION = YES;
233+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
234+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
235+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
236+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
237+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
238+
CLANG_WARN_STRICT_PROTOTYPES = YES;
239+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
240+
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
241+
CLANG_WARN_UNREACHABLE_CODE = YES;
242+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
243+
CODE_SIGN_IDENTITY = "Mac Developer";
244+
COPY_PHASE_STRIP = NO;
245+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
246+
ENABLE_NS_ASSERTIONS = NO;
247+
ENABLE_STRICT_OBJC_MSGSEND = YES;
248+
GCC_C_LANGUAGE_STANDARD = gnu11;
249+
GCC_NO_COMMON_BLOCKS = YES;
250+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
251+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
252+
GCC_WARN_UNDECLARED_SELECTOR = YES;
253+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
254+
GCC_WARN_UNUSED_FUNCTION = YES;
255+
GCC_WARN_UNUSED_VARIABLE = YES;
256+
MACOSX_DEPLOYMENT_TARGET = 10.14;
257+
MTL_ENABLE_DEBUG_INFO = NO;
258+
MTL_FAST_MATH = YES;
259+
SDKROOT = macosx;
260+
};
261+
name = Release;
262+
};
263+
DA36488621D652250091DDB2 /* Debug */ = {
264+
isa = XCBuildConfiguration;
265+
buildSettings = {
266+
CODE_SIGN_STYLE = Automatic;
267+
DEVELOPMENT_TEAM = 7465LVKW35;
268+
PRODUCT_NAME = "$(TARGET_NAME)";
269+
};
270+
name = Debug;
271+
};
272+
DA36488721D652250091DDB2 /* Release */ = {
273+
isa = XCBuildConfiguration;
274+
buildSettings = {
275+
CODE_SIGN_STYLE = Automatic;
276+
DEVELOPMENT_TEAM = 7465LVKW35;
277+
PRODUCT_NAME = "$(TARGET_NAME)";
278+
};
279+
name = Release;
280+
};
281+
/* End XCBuildConfiguration section */
282+
283+
/* Begin XCConfigurationList section */
284+
DA36487921D652250091DDB2 /* Build configuration list for PBXProject "iterator" */ = {
285+
isa = XCConfigurationList;
286+
buildConfigurations = (
287+
DA36488321D652250091DDB2 /* Debug */,
288+
DA36488421D652250091DDB2 /* Release */,
289+
);
290+
defaultConfigurationIsVisible = 0;
291+
defaultConfigurationName = Release;
292+
};
293+
DA36488521D652250091DDB2 /* Build configuration list for PBXNativeTarget "iterator" */ = {
294+
isa = XCConfigurationList;
295+
buildConfigurations = (
296+
DA36488621D652250091DDB2 /* Debug */,
297+
DA36488721D652250091DDB2 /* Release */,
298+
);
299+
defaultConfigurationIsVisible = 0;
300+
defaultConfigurationName = Release;
301+
};
302+
/* End XCConfigurationList section */
303+
};
304+
rootObject = DA36487621D652250091DDB2 /* Project object */;
305+
}

da-hua-she-ji-mo-shi/20-iterator/iterator/iterator.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Aggreagate.h
3+
// iterator
4+
//
5+
// Created by 王俊 on 2018/12/28.
6+
// Copyright © 2018 王俊. All rights reserved.
7+
//
8+
9+
#ifndef Aggreagate_h
10+
#define Aggreagate_h
11+
12+
@protocol Iterator;
13+
@protocol Aggregate <NSObject>
14+
15+
@required
16+
- (id<Iterator>)createIterator;
17+
18+
- (NSUInteger)count;
19+
- (id)firstObject;
20+
- (void)addObject:(id)anObject;
21+
- (id)objectAtIndex:(NSUInteger)index;
22+
23+
24+
@end
25+
26+
27+
#endif /* Aggreagate_h */
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// ConcreteAggregate.h
3+
// iterator
4+
//
5+
// Created by 王俊 on 2018/12/28.
6+
// Copyright © 2018 王俊. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "Aggreagate.h"
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@interface ConcreteAggregate : NSObject<Aggregate>
15+
16+
@end
17+
18+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)