【发布时间】:2011-01-14 05:50:00
【问题描述】:
我在 Objective-C 中写了一个 for 循环,这就是我的代码的样子
NSString *string = [NSString stringWithContentsOfFile=@"/Users/Home/myFile.doc"];
NSString *seperator=@"\n";
NSArray *mainarray = [string componentsSeparatedByString:seperator];
// Since i want to parse each element of mainarray
for(NSString *s in mainarray)
{
//again parising the string using a new separator
NSString newseparator = @"=";
NSArray *subarray = [s componentsSeparatedByString : newseparator];
//Copying the elements of array into key and object string variables
NSString *key = [subarray objectAtIndex:0];
NSLog(@"%@",key);
NSString *class_name= [subarray objectAtIndex:1];
NSLog(@"%@",class_name);
// create an instance for the class_name
//dont knw how it ll take the value from file and ???
//Putting the key and objects values into hashtable
NSMutableDictionary = [NSDictionary dictinaryWithObject:class_name forKey:key];
}
每当我执行此代码时,我的程序都会崩溃,因为未捕获的异常 NSRangeException 而终止应用程序
如何知道数组的范围以及如何在for循环中指定终止条件???请告诉我如何处理这个异常???
【问题讨论】:
标签: objective-c arrays exception-handling for-loop