This file contains hidden or 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
struct Donor { | |
let title: String | |
let firstName: String | |
let familyName: String | |
let lastDonation: Float | |
init(_ title:String, _ first:String, _ family:String, _ last:Float) { | |
self.title = title | |
self.firstName = first | |
self.familyName = family |
This file contains hidden or 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
class Sequence { | |
private var numbers: [Int] | |
init(_ numbers: Int...) { | |
self.numbers = numbers | |
} | |
func addNumber(value: Int) { | |
self.numbers.append(value) | |
} |
This file contains hidden or 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
class ActivityLog { | |
func logActivity(activity: String) { | |
print("Log: \(activity)") | |
} | |
} | |
class FileCache { | |
func loadFiles(user: String) { | |
print("Load files for \(user)") | |
} |
This file contains hidden or 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
class Calculator { | |
private (set) var total = 0 | |
func add(amount: Int) { | |
total += amount | |
} | |
func subtract(amount: Int) { | |
total -= amount | |
} |
This file contains hidden or 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
struct Message { | |
let from: String | |
let to: String | |
let subject: String | |
} | |
class LocalTransmitter { | |
func sendMessage(message: Message) { | |
print("Message to \(message.to) sent locally") | |
} |
This file contains hidden or 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
func getHeader(header:String) { | |
let url = NSURL(string: "http://www.apress.com") | |
let request = NSURLRequest(URL: url!) | |
NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { data, response, error in | |
if let httpResponse = response as? NSHTTPURLResponse { | |
if let headerValue = httpResponse.allHeaderFields[header] as? NSString { | |
print("\(header): \(headerValue)") | |
} | |
} | |
}).resume() |
This file contains hidden or 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
class TreasureMap { | |
enum Treasures { | |
case GALLEON | |
case BURIED_GOLD | |
case SUNKEN_JEWELS | |
} | |
struct MapLocation { | |
let gridLetter: Character |
This file contains hidden or 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
class Purchase : CustomStringConvertible { | |
private let product:String | |
private let price:Float | |
init(product:String, price:Float) { | |
self.product = product | |
self.price = price | |
} | |
var description:String { |
This file contains hidden or 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
protocol ClearMessageChannel { | |
func send(message:String) | |
} | |
protocol SecureMessageChannel { | |
func sendEncryptedMessage(encryptedText:String) | |
} | |
class Communicator { | |
private let clearChannel:ClearMessageChannel |
This file contains hidden or 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
struct Employee { | |
var name:String | |
var title:String | |
} | |
protocol EmployeeDataSource { | |
var employees:[Employee] { get } | |
func searchByName(name:String) -> [Employee] | |
func searchByTitle(title:String) -> [Employee] | |
} |