2014年9月11日木曜日

開発環境

Head First JavaScript Programming (Eric T. Freeman (著)、 Elisabeth Robson (著)、 O'Reilly Media )のChapter 10(Liberated functions: First Class Functions)、SHARPEN YOUR PENCIL(p.453)をSwiftで考えてみる。

SHARPEN YOUR PENCIL(p.453)

コード(Xcode)

main.swift

//
//  main.swift
//  sample445
//
//  Created by kamimura on 9/8/14.
//  Copyright (c) 2014 kamimura. All rights reserved.
//

import Foundation

struct Passenger {
    let name:String
    let paid:Bool
}

let passengers:[Passenger] = [
    Passenger(name: "Jane Doloop", paid: true),
    Passenger(name: "Dr. Evel", paid: true ),
    Passenger(name: "Sue Property", paid: false),
    Passenger(name: "John Funcall", paid: true)
]

func checkNoFlyList(passenger:Passenger) -> Bool {
    return passenger.name == "Dr. Evel"
}

func checkNotPaid(passenger:Passenger) -> Bool {
    return !passenger.paid
}

for passenger in passengers {
    println("\(passenger.name) \(checkNoFlyList(passenger)) \(checkNotPaid(passenger))")
}

入出力結果(Console Output)

15
10010
105
10100
Program ended with exit code: 0

0 コメント:

コメントを投稿