I had the following code:
NSData * JSONData = [MyJSON dataWithJSONObject:highlightItemsArray];
if ([JSONData isNotNull]){
NSError *error;
BOOL writeToDiskSuccess = [JSONData writeToFile:self.highlightDiskCachePath_ options:NSDataWritingAtomic error:&error];
if (!writeToDiskSuccess){
NSLog(@"Writing appended caption failed %@", error);
} else {
NSLog(@"Writing appended caption succeed");
}
}
However, this returns NO and error here when printed is null. How can I figure out what’s wrong?
I think you need to add more detail to get an answer here.
I’m assuming you get writeToDiskSuccess = FALSE? if so first thing I’d be looking at is if you’re writing to the wrong directory by mistake… can you give the value of self.highlightDiskCachePath_ ? Also do you get the same error on the simulator? If so you should be able to navigate there in Finder to see if there is a missing path element or some other disk issue with why it can’t write there.
Finally I’d check that it isn’t something specific to JSONData writeToFile failing… can you write a simple text file to the location you’re trying to write this to?
Also it may be worth noting anything in the console output that may be out of the ordinary, when these things fail you sometimes get a clue there.