NSFileManager can be used to find out the size of a file, specifically: attributesOfItemAtPath which returns a dictionary that has fileSize information.
As i said, i want to know the size of the future file before i save the content of NSString to a file on my disk.
The size on disk is going to depend on what encoding you use to write it to disk.
The size on disk is going to depend on what encoding you use to write it to disk.
encoding:NSUTF8StringEncoding
This page from CocoaDev answers the question thoroughly:
http://www.cocoadev.com/index.pl?FileSize
Short answer: you can use NSString's lengthOfBytesUsingEncoding: to get the number of bytes, but the actual size of that file on disk will dependant on other factors. As others have said, it will be useful to know why you need this information so we can suggest a suitable solution.
Thanks for guidance,
my nsstring object is loaded by html contents. how would be the solution in this case?
What makes you think there is a difference? Asked before, but what is it actually that you try to achieve? Usually, after people have tried for ages answering your questions, it then turns out that you asked the completely wrong questions in the first place.
The XY Problem
.. You want to do X, and you think Y is the best way of doing it.
.. Instead of asking about X, you ask about Y.