【发布时间】:2014-12-13 12:35:10
【问题描述】:
试图将目标 c 转换为 swift 感到非常沮丧。我有以下适用于目标 c 的代码。
NSMutableArray *path = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Sequence List" ofType:@"plist"]];
//Shuffle the array of questions
numberSequenceList = [self shuffleArray:path];
currentQuestion = currentQuestion + 1;
if (Round==1) {
//Take first object in shuffled array as the first question
NSMutableArray *firstQuestion = [[NSMutableArray alloc] initWithArray:[numberSequenceList objectAtIndex:0]];
//Find question and populate text view
NSString *string = [firstQuestion objectAtIndex:0];
self.lblNumber.text = string;
//Find and store the answer
NSString *findAnswer = [firstQuestion objectAtIndex:1];
Answer = [findAnswer intValue];
}
但我似乎无法让它快速工作。我可以使用
拉出 plist 的内容var path = NSBundle.mainBundle().pathForResource("Sequence List", ofType: "plist")
但我看不到在 swift 中有与 objectAtIndex 等价的东西。如果我尝试以下操作,我会收到一条错误消息,提示“字符串没有名为下标的成员”,这显然意味着我需要解开路径。
let firstQuestion = path[0]
【问题讨论】: