tw-oocamp-201512 / the-code-of-you

使用你最喜欢的语言写一段代码来介绍你自己,提交在Issues里
1 stars 1 forks source link

Zhu Xueliang's introduction #4

Open iossocket opened 9 years ago

iossocket commented 9 years ago
// Please run it with Swift 2.1 and Xcode 7.1

import Foundation

let greeting = "Hello everyone, this is my introduction"

extension Array {
    func getTheContentOfArray() -> String {
        return String(self).stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "[]"))
    }
}

enum Gender {
    case male
    case female
}

protocol Hobby {
    func doSth()
}

struct Coding: Hobby {
    func doSth() {
        print("I love coding...")
    }
}

struct Music: Hobby {
    func doSth() {
        print("I love music...")
    }
}

protocol TWer {
    var name: String { get }
    var gender: Gender { get }
    var graduateTime: String { get }
    var beingTWer: String { get }
    var favoriteTech: [String] { get }
    var booksForNow: [String] { get }

    func description()
}

struct ZhuXueliang: TWer {
    var name: String
    var gender: Gender
    var graduateTime: String
    var beingTWer: String
    var favoriteTech: [String]
    var booksForNow: [String]

    var myHobby: [Hobby]?

    func description() {
        basicInfo()
        additionInfo()
        hobbyInfo()
    }

    private func basicInfo() {
        print("My name is " + self.name + ", Gender: " + String(self.gender) + "; and being a TWer about " + beingTWer)
    }

    private func additionInfo() {
        print("About my favorite tech is " + favoriteTech.getTheContentOfArray())
        print("About the books for now is " + booksForNow.getTheContentOfArray())
    }

    private func hobbyInfo() {
        if let hobby = myHobby where hobby.count > 0 {
            print("My hobby are: ")
            for item in hobby {
                item.doSth()
            }
        } else {
            print("I do not have any hobby.")
        }
    }
}

let zxl = ZhuXueliang(name: "Zhu Xueliang", gender: .male, graduateTime: "2013-07-05", beingTWer: "2 months", favoriteTech: ["iOS", "Swift"], booksForNow: ["Clean Code", "The Docker Book", "深入浅出NodeJs"], myHobby: [Coding(), Music()])

zxl.description()
iossocket commented 9 years ago

大家好~ 我叫朱学亮,13年毕业于西安交大,从事软件开发工作大概有一年多,来我厂两个多月了,目前在做iOS的项目~ 热爱Coding~ 很高兴认识大家~^_^