Skip to content

Commit d726b87

Browse files
author
Oktawian Chojnacki
committed
Merge branch 'LazyGetter-master'
* LazyGetter-master: Generator type alias not required
2 parents 99828ba + 856dd11 commit d726b87

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

Design-Patterns.playground.zip

0 Bytes
Binary file not shown.

Design-Patterns.playground/contents.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ A short cheat-sheet with Xcode 6.3beta Playground ([Design-Patterns.playground.z
1616
* [Creational](#creational)
1717
* [Structural](#structural)
1818

19-
*//*:
19+
*/
20+
/*:
2021
Behavioral
2122
==========
2223

2324
>In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.
2425
>
2526
>**Source:** [wikipedia.org](http://en.wikipedia.org/wiki/Behavioral_pattern)
26-
*//*:
27+
*/
28+
/*:
2729
🐝 Chain Of Responsibility
2830
--------------------------
2931

@@ -535,7 +537,8 @@ Creational
535537
> In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.
536538
>
537539
>**Source:** [wikipedia.org](http://en.wikipedia.org/wiki/Creational_pattern)
538-
*//*:
540+
*/
541+
/*:
539542
🌰 Abstract Factory
540543
-------------------
541544

@@ -781,7 +784,8 @@ Structural
781784
>In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities.
782785
>
783786
>**Source:** [wikipedia.org](http://en.wikipedia.org/wiki/Structural_pattern)
784-
*//*:
787+
*/
788+
/*:
785789
🔌 Adapter
786790
----------
787791

@@ -894,7 +898,8 @@ protocol Shape {
894898
}
895899
/*:
896900
Leafs
897-
*/
901+
*/
902+
898903
class Square : Shape {
899904
func draw(fillColor: String) {
900905
print("Drawing a Square with color \(fillColor)")
@@ -1124,4 +1129,4 @@ Info
11241129

11251130
🚀 How to generate playground (+zip) from source: [GENERATE.md](https://github.com/ochococo/Design-Patterns-In-Swift/blob/master/GENERATE.md)
11261131

1127-
*/
1132+
*/

Design-Patterns.playground/playground.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.

docs/behavioral/iterator.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
##🍫 Iterator
2+
3+
The iterator pattern is used to provide a standard interface for traversing a collection of items in an aggregate object without the need to understand its underlying structure.
4+
5+
**Example:**
6+
7+
```swift
8+
struct Cart<T> {
9+
let items: [T]
10+
}
11+
12+
extension Cart: SequenceType {
13+
14+
func generate() -> GeneratorOf<T> {
15+
var i = 0
16+
return GeneratorOf { return i >= self.items.count ? nil : self.items[i++] }
17+
}
18+
}
19+
```
20+
21+
***Usage***
22+
```swift
23+
let cart = Cart(items: ["foo", "bar", "baz"])
24+
25+
for item in cart {
26+
println(item)
27+
}
28+
```

0 commit comments

Comments
 (0)