I was simply experimenting with Swift, so I threw together this in my playground:
// Playground - noun: a place where people can play
import Cocoa
func printCarInfo(car:Car?) -> Void {
if let _car = car {
println("This is a " + _car.make + " " + _car.model + " from \(_car.year). It's worth $" + _car.price + ".")
}
}
class Car {
init(make:String, model:String, year:UInt, color:NSColor, price:UInt) {
self.make = make
self.model = model
self.year = year
self.color = color
self.price = price
}
var make : String
var model : String
var year : UInt
var color : NSColor
var price : UInt
func isNewCar() -> Bool {
let _formatter = NSDateFormatter()
_formatter.dateFormat = "yyyy"
let _currentYear = _formatter.stringFromDate(NSDate())
return (_currentYear == String(self.year))
}
}
let chevy = Car(make: "Chevrolet", model: "Camaro ZL1", year: 2014, color: NSColor.redColor(), price: 55355)
printCarInfo(chevy)
Very straight forward code, there's nothing complicated about it. But Xcode doesn't execute it. The little loading indicator in the bottom right keeps spinning, my macbook gets hot, the fans spin up, and nothing's happening. If I modify the println
command in the printCarInfo(car:Car?) -> Void
function to something like this:
println("Ok")
Then it's totally fine. But as soon as I put this line in:
println("This is a " + _car.make + " " + _car.model + " from \(_car.year). It's worth $" + _car.price + ".")
Xcode freezes like I described above. I tried saving the playground and reopening it, but the same thing happens every time.
I don't think there's anything wrong with the code. Is is just a bug in Xcode beta? Can anyone try to paste this into a playground and see what happens? It's an OS X playground and I use Xcode beta 5. Also, I'm on 10.10 DP5.