Created
November 29, 2016 20:04
-
-
Save JashuaCovington/e3e65e281301798b23b52cb59d10043d to your computer and use it in GitHub Desktop.
SuperHero Swift / Just tinkering
This file contains 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
//: Playground - noun: a place where people can play | |
//: Created By: Jashua Covington 4/11/2016 | |
import UIKit | |
public class SuperHero { | |
public let name: String | |
var birthYear: Int | |
var solo: String | |
var groupName: String | |
private var sneakersField = "Not Specified" | |
internal var sneakers: String { | |
get{ | |
return sneakersField | |
} | |
set { | |
sneakersField = newValue.uppercased() | |
} | |
} | |
var age: Int { | |
get{ | |
let date = NSDate() | |
let calendar = NSCalendar.current | |
let components = calendar.components([.Day, .Month, .Year], fromDate: date) | |
return components.year - birthYear | |
} | |
set { | |
let date = NSDate() | |
let calendar = NSCalendar.current | |
let components = calendar.components([.Year], fromDate: date) | |
self.birthYear = components.year - newValue | |
} | |
} | |
public var runningSpeedScore: Int { | |
willSet { | |
print("The current value for running speed score is:\(runningSpeedScore)") | |
print("I will set the new value for the running Speed Score to: \(newValue)") | |
} | |
didSet { | |
print("I have set the new value for running speed score to: \(runningSpeedScore)") | |
} | |
} | |
init(name: String, birthYear: Int, solo: String, groupName: String, sneakers: String, runningSpeedScore: Int) { | |
self.name = name | |
self.birthYear = birthYear | |
self.solo = solo | |
self.groupName = groupName | |
self.runningSpeedScore = runningSpeedScore | |
self.sneakers = sneakers | |
} | |
} | |
var antMan = SuperHero(name: "Ant-Man", birthYear: 1975, solo: "stand-alone/member", groupName: "Avengers", sneakers: "Running", runningSpeedScore: 20) | |
print(antMan.name) | |
print(antMan.birthYear) | |
print(antMan.age) | |
print(antMan.solo) | |
print(antMan.groupName) | |
print(antMan.runningSpeedScore) | |
print(antMan.sneakers) | |
var spiderMan = SuperHero(name: "Spider-Man", birthYear: 1981, solo: "stand-alone/Cross-Over", groupName: "Avengers, X-Men, Fantastic Four", sneakers: "Jumping", runningSpeedScore: 21) | |
print(spiderMan.name) | |
print(spiderMan.birthYear) | |
print(spiderMan.age) | |
print(spiderMan.solo) | |
print(spiderMan.groupName) | |
print(spiderMan.runningSpeedScore) | |
print(spiderMan.sneakers) | |
var popEye = SuperHero(name: "PopEye", birthYear: 1972, solo: "stand-Alone", groupName: "N/A", sneakers: "Running", runningSpeedScore: 8) | |
print(popEye.name) | |
print(popEye.birthYear) | |
print(popEye.age) | |
print(popEye.solo) | |
print(popEye.runningSpeedScore) | |
print(popEye.groupName) | |
print(popEye.sneakers) | |
var silverSurfer = SuperHero(name: "SilverSurfer", birthYear: 2362, solo: "stand-alone/Cross-Over", groupName: "Avengers, X-Men, Fantastic Four", sneakers: "Air Surfing", runningSpeedScore: 30) | |
print(silverSurfer.name) | |
print(silverSurfer.birthYear) | |
print(silverSurfer.age) | |
print(silverSurfer.solo) | |
print(silverSurfer.groupName) | |
print(silverSurfer.runningSpeedScore) | |
print(silverSurfer.sneakers) | |
antMan.age = 33 | |
print(antMan.age) | |
print(antMan.birthYear) | |
spiderMan.age = 22 | |
print(spiderMan.age) | |
print(spiderMan.birthYear) | |
popEye.age = 47 | |
print(popEye.age) | |
print(popEye.birthYear) | |
silverSurfer.age = 16 | |
print(silverSurfer.age) | |
print(silverSurfer.birthYear) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment