Skip to content

Instantly share code, notes, and snippets.

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
class Sequence {
private var numbers: [Int]
init(_ numbers: Int...) {
self.numbers = numbers
}
func addNumber(value: Int) {
self.numbers.append(value)
}
class ActivityLog {
func logActivity(activity: String) {
print("Log: \(activity)")
}
}
class FileCache {
func loadFiles(user: String) {
print("Load files for \(user)")
}
class Calculator {
private (set) var total = 0
func add(amount: Int) {
total += amount
}
func subtract(amount: Int) {
total -= amount
}
struct Message {
let from: String
let to: String
let subject: String
}
class LocalTransmitter {
func sendMessage(message: Message) {
print("Message to \(message.to) sent locally")
}
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()
class TreasureMap {
enum Treasures {
case GALLEON
case BURIED_GOLD
case SUNKEN_JEWELS
}
struct MapLocation {
let gridLetter: Character
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 {
protocol ClearMessageChannel {
func send(message:String)
}
protocol SecureMessageChannel {
func sendEncryptedMessage(encryptedText:String)
}
class Communicator {
private let clearChannel:ClearMessageChannel
struct Employee {
var name:String
var title:String
}
protocol EmployeeDataSource {
var employees:[Employee] { get }
func searchByName(name:String) -> [Employee]
func searchByTitle(title:String) -> [Employee]
}