let documentUrl: NSURL? = {
return NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first
}
var test: String = {
You wrote this:
var test: String = {
return "String"
}
That is not a computed property. You are initializing your variable test
to a function body (an anonymous function, sometimes called a closure). That isn't what you mean to do. You want to call the function and set the variable test
to the result. The parentheses make that happen; that is how you call a function. Thus:
var test: String = {
return "String"
}()
Thus you define the function and call it, all in one move, and assign the result as the initial value of test
.
If you wanted a computed property, you should have written it like this:
var test: String {
return "String"
}
Notice there is no equal sign. A fuller form would be:
var test: String {
get {
return "String"
}
}