Swift变量亏损值

时间:2014-07-14 01:28:06

标签: arrays variables swift exc-bad-access

我不知道为什么,但元素变量在此方法中完全超出了范围。第一次执行for (index, obj) in enumerate(self)后,元素变量甚至不再在控制台中有一个内存地址,我得到的只是:

(lldb) po element error: <EXPR>:1:1: error: use of unresolved identifier 'element' element ^ <EXPR>:11:5: error: use of unresolved identifier '$__lldb_injected_self'
    $__lldb_injected_self.$__lldb_wrapped_expr_7(     
    ^

//Array extension

func contains<T : Equatable>(element : T) -> Bool
{
    return indexOfObject(element) != nil
}

func indexOfObject<T : Equatable>(element : T) -> Int?
{
    for (index, obj) in enumerate(self) //when this is first executed element variable loses its value. any attempt to access element variable (even outside of this scope) results in EXC_BAD_ACCESS
    {
        let tempObj = obj as T

        if element == tempObj
        {
            return index;
        }
    }

    return nil;
}


//Game.swift

func addGameDelegate <T where T: GameDelegate, T: Equatable> (#gameDelegate : T)
{
    if !_gameDelegates.contains(gameDelegate)
    {
        _gameDelegates += gameDelegate  //EXC_BAD_ACCESS
    }
}

0 个答案:

没有答案