如何在swift中使用objectAtIndex

Sae*_*Kim 6 objective-c ios swift

*IDE:XCODE 6 beta3
*语言:Swift + Objective C

这是我的代码.

目标C代码

@implementation arrayTest
{
    NSMutableArray *mutableArray;
}
- (id) init {
    self = [super init];
    if(self) {
        mutableArray = [[NSMutableArray alloc] init];
    }
    return self;
}
- (NSMutableArray *) getArray {
          ...
    return mutableArray; // mutableArray = {2, 5, 10}
}
Run Code Online (Sandbox Code Playgroud)

SWIFT代码

var target = arrayTest.getArray() // target = {2, 5, 10} 

for index in 1...10 {
    for targetIndex in 1...target.count { // target.count = 3
        if index == target.objectAtIndex(targetIndex-1) as Int { 
            println("GET")
        } else {
            println(index)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要以下结果:

1 GET 3 4 GET 6 7 8 9 GET
Run Code Online (Sandbox Code Playgroud)

但是,我的代码给了我错误

libswift_stdlib_core.dylib`swift_dynamicCastObjCClassUnconditional:
0x107e385b0:  pushq  %rbp
...(skip)
0x107e385e4:  leaq   0xa167(%rip), %rax        ; "Swift dynamic cast failed"
0x107e385eb:  movq   %rax, 0x6e9de(%rip)       ; gCRAnnotations + 8
0x107e385f2:  int3   
0x107e385f3:  nopw   %cs:(%rax,%rax)
Run Code Online (Sandbox Code Playgroud)

.

if index == target.objectAtIndex(targetIndex-1) as Int { 
// target.objectAtIndex(0) = 2 -> but type is not integer
Run Code Online (Sandbox Code Playgroud)

我认为这段代码不完整.但我找不到解决方案.
帮我TT

iOS*_*Guy 20

在Obj-C中,objectAtIndex:2看起来像这样:

[self.myArray ObjectAtIndex:2]
Run Code Online (Sandbox Code Playgroud)

在Swift objectAtIndex:2中如下所示:

self.myArray[2]
Run Code Online (Sandbox Code Playgroud)