kamalbhai
kamalbhai

Reputation: 520

Size of NSString - Objective C

Is there a limit as far as NSString is concerned ?? I am using the following lines of code to read the contents of file edit.txt but saveString is not able to contain all of the contents of my .txt file.

NSString *savedDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

//NSString *savedeDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *saveFilePath = [savedDir stringByAppendingPathComponent:@"Root"];
saveFilePath = [saveFilePath stringByAppendingPathComponent:savedName];
saveFilePath = [saveFilePath stringByAppendingPathComponent:@"edit.txt"];
NSString *saveString = [NSString stringWithContentsOfFile:saveFilePath encoding:NSUTF8StringEncoding error:nil]; 
NSLog(@"saveString is :: %@ savedSpaceName : %@ savefilepath : %@ ", saveString, savedName, saveFilePath);

Is there an issue with the size of NSString ?? I am unable to figure it out. Can someone provide me an explaination or help me to figure it out. Thanks and Regards.

Upvotes: 0

Views: 592

Answers (1)

Kanan Vora
Kanan Vora

Reputation: 2122

I would assume the hard limit for NSString would be NSUIntegerMax characters, since NSString's index and size-related methods return an NSUInteger. Since all devices currently capable of running iOS are 32 bit, this means NSUIntegerMax is 2^32 - 1 and NSString can hold a little over 4.2 billion characters.

As far as I know, the practical limit is much smaller - on an iOS device especially, you'll run out of memory long before you hit any hard limit in NSString.

So your problem is something else!!!

Upvotes: 2

Related Questions