Apple の Swift Programming Language と同じ次のコードを書きましたが、次のような予期しないエラーが発生しました: type'()' does not conform to protocol 'boolean type' , その場所は次のコードに示されています:
class Person1 {
var residence:Residence?
}
class Residence {
var rooms=[Room]()
var numberOfRooms:Int{
return rooms.count
}
subscript(i:Int)->Room{
get{
return rooms[i]
}
set{
rooms[i]=newValue
}
}
func printNumberOfRooms(){
println("the number of rooms is \(numberOfRooms)")
}
var address:Address?
}
class Room {
var name:String
init(name:String){
self.name=name
}
}
class Address {
var builingNumber:String?
var buildingName:String?
var street:String?
func buildingIdentifier()->String?{
if buildingName!=nil {return buildingName} Error:type'()' does not conform to protocol 'boolean type'
else if builingNumber!=nil {return builingNumber}
else {return nil}
}
}