Question: 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'
> 
> 
>

Answer: 
Your results variable needs to be of type AnyObject instead of [AnyObject]. Basically, you need to cast the array of AnyObjects to a single AnyObject

```
func someFunc(isList:Bool=false) -> AnyObject {
    if isList {
        var results: AnyObject = [11, "123", [], "22"]
        return results
    } else {
        var result = "123"
        return result
    }
}

```
Can you make it return Any?

```
func something(list: Bool = false) -> Any {
  if list {
    return [11, "123", [], "22"]
  } else {
    return "123"
  }
}

let result = something(true)
let result0 = something(false)

```

Any can represent an instance of any type at all, including function types.

The apple documentation suggests against using the **Any** protocol in this manner.

> 
> **Note:** Use Any and AnyObject only when you explicitly need the behavior and capabilities they provide. It is always better to be specific about the types you expect to work with in your code.
> 
> 
> 

[Apple Reference](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TypeCasting.html#//apple_ref/doc/uid/TP40014097-CH22-ID342)