简体   繁体   中英

Swift - Ambiguous use of subscript sort() - Xcode 7.3

I have updated my Xcode to version 7.3, which is compatible with iOS 9.3. My sort() method, which is let sortArr = saveDeals?.sort({ $1[2] as! String > $0[2] as! String}); , is giving me an "ambiguous use of subscript" error. Please let me know what I can do to fix this error. Thank you!

func sortSaveDealsArr(saveDeals: [AnyObject]?) -> [AnyObject]
{
    let sortArr = saveDeals?.sort({ $1[2] as! String > $0[2] as! String});
    return sortArr!;
}

The problem is that saveDeals is typed as a [AnyObject]? . Thus your $0 and $1 are each an AnyObject, and you can't subscript an AnyObject. You need to cast each of these things to something that is itself subscriptable. I don't know what's in your array so I can't say what that would be. Is saveDeals an array of arrays? If so, you need to cast saveDeals to that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM