I have a function that should return String or Array:
func someFunc(isList:Bool=false) -> AnyObject {
if isList {
var results:[AnyObject] = [11, "123", [], "22"]
return results
} else {
var result = "123"
return result
}
}
But compiler says:
Return expression of type '[AnyObject]' does not conform to 'AnyObject'
isListis false, return an array with only a string in it? Or why not just make the return variable optional and returnnilin some cases, as it doesn't look like you're actually using the return string for anything.if isList { var results:[Kanna.XMLElement] = [] for node in doc.xpath(xpath) { results.append(node) } return results }Return expression of type '[XMLElement]' does not conform to 'AnyObject'