I have a function that checks whether the plist exists or not, if not it will create the plist.
this function is called in background i.e
[self performSelectorInBackground:@selector(CreatePlist:) withObject:xyz];
everything goes just perfect.
but when i try to fetch the data from the plist on main thread i.e
NSString *path = [[NSBundle mainBundle] pathForResource:@"calendar" ofType:@"plist"];
NSLog(@"path is %@", path); // path comes null
fileName = [fileName stringByReplacingOccurrencesOfString:@"/" withString:@""];
NSLog(@"file name data contain %@",fileName);
NSFileManager *fileManager = [NSFileManager defaultManager];
//see if Data.plist exists in the Documents directory
if (![fileManager fileExistsAtPath:[self saveMyPath:fileName] ]) {
[fileManager copyItemAtPath:path toPath:[self saveMyPath:@""] error:nil]; //at this point the app crashes saying path is null
}
when i moved my application from the background to the main thread it works well.
what is the problem here.?
looks like the background thread isn’t finished when the main thread gets to it.
you could try using grand central dispatch.. e.g.