我目前正在学习Objective-C。我正在学习的这本书给了我一个挑战,在这里我给了两个数组,我应该创建一个程序来显示在这两个数组中列出的对象。Objective-C两个阵列之间的匹配对象
我已经设置好了一切,唯一困难的是比较两个数组并返回两个数组中出现的内容。他们都是很长的名单,而我所有的尝试都没有出现,甚至崩溃。
如何做到这一点的任何帮助将是伟大的。
编辑:这是我到目前为止所做的...我不能举出我之前尝试过的例子,因为我会使用诸如isEqualToString:,predicateWithFormat:之类的东西,并且在它没有我会删除代码。
我很抱歉,如果我的代码包含明显的错误,让我再次提到我是新的。
{ @autoreleasepool {
// Read in a file as a huge string (ignoring the possibility of an error)
NSString *nameString =
[NSString stringWithContentsOfFile:@"/usr/share/dict/propernames"
encoding:NSUTF8StringEncoding
error:NULL];
// Read in a file for words
NSString *wordString =
[NSString stringWithContentsOfFile:@"/usr/share/dict/words"
encoding:NSUTF8StringEncoding
error:NULL];
// Break it into an array of strings
NSArray *namesArray = [nameString componentsSeparatedByString:@"\n"];
// Break words into an array of strings
NSArray *wordArray = [wordString componentsSeparatedByString:@"\n"];
// Go through the array one string at a time
for (NSString *n in namesArray) {
// Here is where I'm at
}
}
}
的可能的复制[this](http://stackoverflow.com/a/1138417/1215715) – Ryan
请提供您尝试过的示例代码。 – sarin