Created
September 5, 2016 11:01
-
-
Save Darmaal/2f69a7242c2deba5c863980c2e3a7834 to your computer and use it in GitHub Desktop.
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
import Foundation | |
class PlanetarySystem { | |
let name:String | |
let planets:[Planet] | |
//computed properties -> curely braces -> always return something | |
var randomPlanet:Planet? { | |
if planets.isEmpty { | |
return nil | |
} else { | |
//creating a variable to select a random planet | |
let index = Int(arc4random_uniform(UInt32(planets.count))) | |
return planets[index] | |
} | |
} | |
init (name:String, planets:[Planet]){ | |
self.name = name | |
self.planets = planets | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment