Skip to content

Instantly share code, notes, and snippets.

@Darmaal
Created September 5, 2016 11:01
Show Gist options
  • Save Darmaal/2f69a7242c2deba5c863980c2e3a7834 to your computer and use it in GitHub Desktop.
Save Darmaal/2f69a7242c2deba5c863980c2e3a7834 to your computer and use it in GitHub Desktop.
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