# Ambiguous Subscript

**URL:** <https://forums.kodeco.com/t/ambiguous-subscript/172219>\
**Category:** Swift Apprentice\
**Created:** [May 31, 2022, 4:27am UTC](https://forums.kodeco.com/t/ambiguous-subscript/172219 "2022-05-31T04:27:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jinkazama](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jinkazama/32/105896_2.png) [@jinkazama](https://forums.kodeco.com/u/jinkazama)\
**Post date:** [May 31, 2022, 4:27am UTC](https://forums.kodeco.com/t/ambiguous-subscript/172219/1 "2022-05-31T04:27:21Z")

</div>

```auto
extension Array {
    subscript(i index: Int) -> (String, String)? {
        guard let value = self[index] as? Int else {
            return nil
        }
        
        switch (value >= 0, abs(value % 2)) {
        case (true, 0): return ("positive", "even")
        case(true, 1): return ("positive", "odd")
        case(false, 0): return ("negative", "even")
        case(false, 1): return ("negative", "odd")
        default: return nil
            
        }
    }
}

```

How come the code above works but the code below doesn’t work and keeps saying ambiguous subscript?

```auto
extension Array {
    subscript(i: Int) -> (String, String)? {
        guard let value = self[i] as? Int else {
            return nil
        }
        
        switch (value >= 0, abs(value % 2)) {
        case (true, 0): return ("positive", "even")
        case(true, 1): return ("positive", "odd")
        case(false, 0): return ("negative", "even")
        case(false, 1): return ("negative", "odd")
        default: return nil
            
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![kpere](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kpere/32/109586_2.png) [@kpere](https://forums.kodeco.com/u/kpere)\
**Post date:** [May 31, 2022, 3:32pm UTC](https://forums.kodeco.com/t/ambiguous-subscript/172219/2 "2022-05-31T15:32:21Z")

</div>

@shogunkaramazov any suggestions?

---

<div class="post-metadata">

**Author:** ![jayantvarma](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jayantvarma/32/111768_2.png) [@jayantvarma](https://forums.kodeco.com/u/jayantvarma)\
**Post date:** [June 1, 2022, 12:57am UTC](https://forums.kodeco.com/t/ambiguous-subscript/172219/3 "2022-06-01T00:57:59Z")

</div>

Hi @jinkazama ,  
it is an interesting one, I could be wrong but it has something to do with the compiler and the parameter names.

If I change the second function block as `subscript(i i : Int) -> ` it works, so what I can say at a surface level is that it needs an internal variable in this scenario.

The generated interface for this looks like  
`internal subscript(i i: Int) -> (String, String)? { get }`  
where as the compiler fails to generate the interface for the second block without an internal parameter.

i think it has something to do with the Swift Compiler and/or a clash with the default array subscript signature.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [November 13, 2022, 8:27pm UTC](https://forums.kodeco.com/t/ambiguous-subscript/172219/4 "2022-11-13T20:27:32Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
