我正在尝试从记录超过 10000 个的 plist 文件中读取,但是每当我运行它时,它就会崩溃,这是我正在使用的代码,它无法从 plist 中读取
-(IBAction)clicked:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"news" ofType:@"plist"];
NSMutableArray *array = [NSMutableArray arrayWithContentsOfFile: path];
然后我使用排序程序.....
但以上在这里不起作用也是他的plist文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>4</string>
<string>2</string>
<string>5</string>
<string>8</string>
<string>1</string>
</array>
</plist>
@implementation sort_algViewController
-(IBAction)clicked:(id)sender{
//id temp;
NSString *path = [[NSBundle mainBundle] pathForResource:
@"news" ofType:@"plist"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSLog(@"%@",path);
printf("YeS");
}
//NSMutableArray *array = [[NSArray arrayWithObjects: @"1", @"9", @"7",@"3", @"5", nil]mutableCopy];
//myarray = [NSMutableArray arrayWithContentsOfFile: @"bdata.txt" ];
NSMutableArray *array = [NSMutableArray arrayWithContentsOfFile: path];
// NSString *array = [NSString stringWithContentsOfFile: path];
NSAutoreleasePool *pool = [NSAutoreleasePool new];
// NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSLog(@"%@",array);
NSLog(@"%@",path);
//printf("before Array x: ");
//bubbleSort(array); // sort the array
int n = [array count] ;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if ([[array objectAtIndex: j] compare:
[array objectAtIndex: j+1]] == NSOrderedDescending)
//#define SWAP(arr, x, y)
do {
id oldX = [array objectAtIndex: (j)];
[array replaceObjectAtIndex: (j) withObject: [array objectAtIndex: (j+1)]];
[array replaceObjectAtIndex: (j+1) withObject: oldX];
} while (0);
printf("array");
NSString *element;
NSEnumerator *iterator = [array objectEnumerator];
while ((element = [iterator nextObject]) != nil)
printf("%s ", [element UTF8String]);
printf("\n");
[array release]; // array needs to be released!
[pool release];
//return EXIT_SUCCESS;
}