2014年9月24日水曜日

開発環境

Head First JavaScript Programming (Eric T. Freeman (著)、 Elisabeth Robson (著)、 O'Reilly Media )のChapter 12(Creating object: Advanced Object Construction)、BE THE BROWSER(p.529)をSwiftで考えてみる。

BE THE BROWSER(p.529)

コード(Xcode)

main.swift

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

import Foundation

struct Widget:Printable {
    let no:Int
    let size:String
    var description:String {return "\(no), \(size)"}
}

struct FormFactor:Printable {
    let material:String
    let widget:Widget
    var description:String {return "\(material), \(widget)"}
}

let widget_a:Widget = Widget(no: 100, size: "large")
let widget_b:Widget = Widget(no: 101, size: "small")
let form_factor_a:FormFactor = FormFactor(material: "plastic", widget: widget_a)
let form_factor_b:FormFactor = FormFactor(material: "metal", widget: widget_b)

println(form_factor_a)
println(form_factor_b)

入出力結果(Console Output)

plastic, 100, large
metal, 101, small
Program ended with exit code: 0

0 コメント:

コメントを投稿