I'm pulling a .json file from my server and trying to read it into an NSDictionary in my app. Some of the file is being correctly parsed but it is incomplete - only some of the file is being read.
The strange thing is that the NSData is an equal length to the actual file, so it seems that it has full access, at least at some stage. When I log the NSData however, it seems to be way too short for the size of the file.
Here's the code I'm using to find the bug:
//SYNC BOOL
if (isSyncing){ return; }
isSyncing = true;
//FETCH BOOTSTRAP
NSError * fetchError = nil;
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:syncPath]
options:kNilOptions
error:&fetchError];
if (fetchError){ [self error]; return; }
//PARSE JSON
NSError * jsonError = nil;
NSDictionary * json = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&jsonError];
if (jsonError){ [self error]; return; }
NSLog(@"data length is %lu", data.length);
NSLog(@"json is %@", json);
I've tried loading remotely from the server and locally from NSBundle - same result.
Could this be related to encoding / a rogue character in the JSON / some NSData max length?
Those options on the NSData fetch method and JSON Serialisation method, I've always left blank with no issue in the past, in terms of what's being pulled it's the same. I've also tried requests and sessions etc with no love.
EDIT: I should add that when I log the the .allKeys of the json dictionary, it returns all keys correctly (including those not included in the log of the dictionary itself). This coupled with the correct NSData length implies that the data is in fact there, in completion. An explanation would be if the NSLog itself is somehow being truncated, implying an error when none exists. The problem is I haven't changed anything there. It could be a beta bug in the new Xcode.
EDIT B: Logger Error on Xcode 9?
NSString * string = @"";
for (int n = 0; n < 10000; n++){
string = [NSString stringWithFormat:@"%@ %i",string,n];
}
NSLog(@"string is %@", string);
Outputs to 6.7k not 10k.