forked from ochococo/Design-Patterns-In-Swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging upstream/master and regenerating playground file
- Loading branch information
Showing
60 changed files
with
569 additions
and
97 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Section 48</title> | ||
<meta id="xcode-display" name="xcode-display" content="render"> | ||
<meta name="apple-mobile-web-app-capable" content="yes"> | ||
<meta name="viewport" content="width=device-width, maximum-scale=1.0"> | ||
<link rel="stylesheet" type="text/css" href="stylesheet.css"> | ||
</head> | ||
<body> | ||
<div class="content-wrapper"> | ||
<section class="section"> | ||
<h2 id="visitor">Visitor</h2> | ||
|
||
</section> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Section 50</title> | ||
<meta id="xcode-display" name="xcode-display" content="render"> | ||
<meta name="apple-mobile-web-app-capable" content="yes"> | ||
<meta name="viewport" content="width=device-width, maximum-scale=1.0"> | ||
<link rel="stylesheet" type="text/css" href="stylesheet.css"> | ||
</head> | ||
<body> | ||
<div class="content-wrapper"> | ||
<section class="section"> | ||
<p><strong>Usage:</strong></p> | ||
|
||
</section> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version="3.0" sdk="macosx" allows-reset="YES"> | ||
<playground version='3.0' sdk='macosx' allows-reset='YES'> | ||
<sections> | ||
<code source-file-name="section-0.swift"> | ||
</code> | ||
<documentation relative-path="section-1.html"> | ||
</documentation> | ||
<code source-file-name="section-2.swift"> | ||
</code> | ||
<documentation relative-path="section-3.html"> | ||
</documentation> | ||
<code source-file-name="section-4.swift"> | ||
</code> | ||
<documentation relative-path="section-5.html"> | ||
</documentation> | ||
<code source-file-name="section-6.swift"> | ||
</code> | ||
<documentation relative-path="section-7.html"> | ||
</documentation> | ||
<code source-file-name="section-8.swift"> | ||
</code> | ||
<documentation relative-path="section-9.html"> | ||
</documentation> | ||
<code source-file-name="section-10.swift"> | ||
</code> | ||
<documentation relative-path="section-11.html"> | ||
</documentation> | ||
<code source-file-name="section-12.swift"> | ||
</code> | ||
<documentation relative-path="section-13.html"> | ||
</documentation> | ||
<code source-file-name="section-14.swift"> | ||
</code> | ||
<documentation relative-path="section-15.html"> | ||
</documentation> | ||
<code source-file-name="section-16.swift"> | ||
</code> | ||
<documentation relative-path="section-17.html"> | ||
</documentation> | ||
<code source-file-name="section-18.swift"> | ||
</code> | ||
<documentation relative-path="section-19.html"> | ||
</documentation> | ||
<code source-file-name="section-20.swift"> | ||
</code> | ||
<documentation relative-path="section-21.html"> | ||
</documentation> | ||
<code source-file-name="section-22.swift"> | ||
</code> | ||
<documentation relative-path="section-23.html"> | ||
</documentation> | ||
<code source-file-name="section-24.swift"> | ||
</code> | ||
<documentation relative-path="section-25.html"> | ||
</documentation> | ||
<code source-file-name="section-26.swift"> | ||
</code> | ||
<documentation relative-path="section-27.html"> | ||
</documentation> | ||
<code source-file-name="section-28.swift"> | ||
</code> | ||
<documentation relative-path="section-29.html"> | ||
</documentation> | ||
<code source-file-name="section-30.swift"> | ||
</code> | ||
<documentation relative-path="section-31.html"> | ||
</documentation> | ||
<code source-file-name="section-32.swift"> | ||
</code> | ||
<documentation relative-path="section-33.html"> | ||
</documentation> | ||
<code source-file-name="section-34.swift"> | ||
</code> | ||
<documentation relative-path="section-35.html"> | ||
</documentation> | ||
<code source-file-name="section-36.swift"> | ||
</code> | ||
<documentation relative-path="section-37.html"> | ||
</documentation> | ||
<code source-file-name="section-38.swift"> | ||
</code> | ||
<documentation relative-path="section-39.html"> | ||
</documentation> | ||
<code source-file-name="section-40.swift"> | ||
</code> | ||
<documentation relative-path="section-41.html"> | ||
</documentation> | ||
<code source-file-name="section-42.swift"> | ||
</code> | ||
<documentation relative-path="section-43.html"> | ||
</documentation> | ||
<code source-file-name="section-44.swift"> | ||
</code> | ||
<documentation relative-path="section-45.html"> | ||
</documentation> | ||
<code source-file-name="section-46.swift"> | ||
</code> | ||
<code source-file-name='section-1.swift'/> | ||
<documentation relative-path='section-1.html'/> | ||
<code source-file-name='section-3.swift'/> | ||
<documentation relative-path='section-3.html'/> | ||
<code source-file-name='section-5.swift'/> | ||
<documentation relative-path='section-5.html'/> | ||
<code source-file-name='section-7.swift'/> | ||
<documentation relative-path='section-7.html'/> | ||
<code source-file-name='section-9.swift'/> | ||
<documentation relative-path='section-9.html'/> | ||
<code source-file-name='section-11.swift'/> | ||
<documentation relative-path='section-11.html'/> | ||
<code source-file-name='section-13.swift'/> | ||
<documentation relative-path='section-13.html'/> | ||
<code source-file-name='section-15.swift'/> | ||
<documentation relative-path='section-15.html'/> | ||
<code source-file-name='section-17.swift'/> | ||
<documentation relative-path='section-17.html'/> | ||
<code source-file-name='section-19.swift'/> | ||
<documentation relative-path='section-19.html'/> | ||
<code source-file-name='section-21.swift'/> | ||
<documentation relative-path='section-21.html'/> | ||
<code source-file-name='section-23.swift'/> | ||
<documentation relative-path='section-23.html'/> | ||
<code source-file-name='section-25.swift'/> | ||
<documentation relative-path='section-25.html'/> | ||
<code source-file-name='section-27.swift'/> | ||
<documentation relative-path='section-27.html'/> | ||
<code source-file-name='section-29.swift'/> | ||
<documentation relative-path='section-29.html'/> | ||
<code source-file-name='section-31.swift'/> | ||
<documentation relative-path='section-31.html'/> | ||
<code source-file-name='section-33.swift'/> | ||
<documentation relative-path='section-33.html'/> | ||
<code source-file-name='section-35.swift'/> | ||
<documentation relative-path='section-35.html'/> | ||
<code source-file-name='section-37.swift'/> | ||
<documentation relative-path='section-37.html'/> | ||
<code source-file-name='section-39.swift'/> | ||
<documentation relative-path='section-39.html'/> | ||
<code source-file-name='section-41.swift'/> | ||
<documentation relative-path='section-41.html'/> | ||
<code source-file-name='section-43.swift'/> | ||
<documentation relative-path='section-43.html'/> | ||
<code source-file-name='section-45.swift'/> | ||
<documentation relative-path='section-45.html'/> | ||
<code source-file-name='section-47.swift'/> | ||
<documentation relative-path='section-47.html'/> | ||
<code source-file-name='section-49.swift'/> | ||
<documentation relative-path='section-49.html'/> | ||
<code source-file-name='section-51.swift'/> | ||
</sections> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Swift | ||
import Foundation |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let uglierPoint = Point{ | ||
$0.x = 0.1 | ||
$0.y = 0.2 | ||
$0.z = 0.3 | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Number | ||
{ | ||
var number:AnyObject | ||
|
||
init(number:AnyObject){ | ||
self.number = number | ||
} | ||
|
||
convenience init(integer:Int){ | ||
self.init(number:integer) | ||
} | ||
|
||
convenience init(double:Double){ | ||
self.init(number:double) | ||
} | ||
|
||
func integerValue() -> Int{ | ||
return self.number as Int | ||
} | ||
|
||
func doubleValue() -> Double{ | ||
return self.number as Double | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let number = Number(double: 12.1) | ||
let double = number.doubleValue() | ||
let integer = number.integerValue() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ThieveryCorporationPersonDisplay{ | ||
|
||
var name:String? | ||
let font:String | ||
|
||
init(font:String){ | ||
self.font = font | ||
} | ||
|
||
func clone() -> ThieveryCorporationPersonDisplay{ | ||
return ThieveryCorporationPersonDisplay(font: self.font) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
let Prototype = ThieveryCorporationPersonDisplay(font:"Ubuntu") | ||
|
||
let Philippe = Prototype.clone() | ||
Philippe.name = "Philippe" | ||
|
||
let Christoph = Prototype.clone() | ||
Christoph.name = "Christoph" | ||
|
||
let Eduardo = Prototype.clone() | ||
Eduardo.name = "Eduardo" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
protocol Currency { | ||
func symbol() -> String | ||
func code() -> String | ||
} | ||
|
||
class Euro : Currency { | ||
func symbol() -> String { | ||
return "€" | ||
} | ||
|
||
func code() -> String { | ||
return "EUR" | ||
} | ||
} | ||
|
||
class UnitedStatedDolar : Currency { | ||
func symbol() -> String { | ||
return "$" | ||
} | ||
|
||
func code() -> String { | ||
return "USD" | ||
} | ||
} | ||
|
||
enum Country { | ||
case UnitedStates, Spain, France, UK | ||
} | ||
|
||
class CurrencyFactory { | ||
class func currencyForCountry(country:Country) -> Currency? { | ||
switch country { | ||
case .Spain, .France : | ||
return Euro() | ||
case .UnitedStates : | ||
return UnitedStatedDolar() | ||
default: | ||
return nil | ||
} | ||
|
||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
let noCurrencyCode = "No Currency Code Available" | ||
|
||
CurrencyFactory.currencyForCountry(.Spain)?.code() ?? noCurrencyCode | ||
CurrencyFactory.currencyForCountry(.UnitedStates)?.code() ?? noCurrencyCode | ||
CurrencyFactory.currencyForCountry(.France)?.code() ?? noCurrencyCode | ||
CurrencyFactory.currencyForCountry(.UK)?.code() ?? noCurrencyCode |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Component | ||
*/ | ||
protocol Shape { | ||
func draw(fillColor:String) | ||
} | ||
|
||
/** | ||
* Leafs | ||
*/ | ||
class Square : Shape { | ||
func draw(fillColor: String) { | ||
print("Drawing a Square with color \(fillColor)") | ||
} | ||
} | ||
|
||
class Circle : Shape { | ||
func draw(fillColor: String) { | ||
print("Drawing a circle with color \(fillColor)") | ||
} | ||
} | ||
|
||
/** | ||
* Composite | ||
*/ | ||
class Whiteboard : Shape { | ||
lazy var shapes = [Shape]() | ||
|
||
init(_ shapes:[Shape]) { | ||
self.shapes = shapes | ||
} | ||
|
||
func draw(fillColor:String) { | ||
for shape in self.shapes { | ||
shape.draw(fillColor) | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var whiteboard = Whiteboard([Circle(), Square()]) | ||
whiteboard.draw("Red") |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Eternal{ | ||
|
||
class func setObject(value: AnyObject!, forKey defaultName: String!){ | ||
let defaults:NSUserDefaults = NSUserDefaults.standardUserDefaults() | ||
defaults.setObject(value,forKey:defaultName) | ||
defaults.synchronize() | ||
} | ||
|
||
class func objectForKey(defaultName: String!) -> AnyObject!{ | ||
let defaults:NSUserDefaults = NSUserDefaults.standardUserDefaults() | ||
return defaults.objectForKey(defaultName) | ||
} | ||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class SingletonClass { | ||
class var shared : SingletonClass { | ||
|
||
struct Static { | ||
static let instance : SingletonClass = SingletonClass() | ||
} | ||
|
||
return Static.instance | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Eternal.setObject("Disconnect me. I’d rather be nothing",forKey:"Bishop") | ||
|
||
Eternal.objectForKey("Bishop") |
File renamed without changes.
Oops, something went wrong.