Last active
October 26, 2015 08:13
-
-
Save Zorgatone/6653d9df4764495a1a22 to your computer and use it in GitHub Desktop.
Swift 2.1 Hello World test
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
// | |
// swift-test-hello.swift | |
// Swift 2.1 tests | |
// | |
//import Foundation | |
class Person { | |
var name: String; | |
var surname: String?; | |
init(name: String, surname: String? = nil) { | |
self.name = name | |
self.surname = surname | |
} | |
func fullname() -> String { | |
if let s = surname { | |
return "\(name) \(s)" | |
} else { | |
return "\(name)" | |
} | |
} | |
} | |
func greeting(person: Person? = nil) { | |
if let p = person { | |
print("Hello, \(p.fullname())!") | |
} else { | |
print("Hello, World!") | |
} | |
} | |
let john = Person(name: "John") | |
//greeting() | |
greeting(john) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment