1

I'm working on finding size of iphone app along with frameworks but I didn't find a way how to do this.can anyone provide me code for this? I got the code of finding current memory usage of my app while running.

link is here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Shreya P
  • 111
  • 1
  • 4
  • Why do you need to know this? I am asking because I believe you are trying to do something which isn't needed. I addition, I don't think this is possible. – dasdom Jul 31 '12 at 06:45
  • 1
    related: http://stackoverflow.com/questions/2188469/calculate-the-size-of-a-folder (just point it at your application bundle) – cobbal Jul 31 '12 at 06:51
  • do you want to check how much ur memory is being used up by your app then you can try this link :- http://stackoverflow.com/questions/6641540/xcode-4-how-to-profile-memory-usage-performance-with-instruments – Leena Jul 31 '12 at 06:54

3 Answers3

1
NSString *folderPath = [[NSBundle mainBundle] bundlePath];
NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil];
NSEnumerator *filesEnumerator = [filesArray objectEnumerator];
NSString *fileName;
unsigned long long int fileSize = 0;

while (fileName = [filesEnumerator nextObject]) {
    NSDictionary *fileDictionary = [[NSFileManager defaultManager] fileAttributesAtPath:[folderPath stringByAppendingPathComponent:fileName] traverseLink:YES];
    fileSize += [fileDictionary fileSize];
}

NSLog(@"App size : %lld",fileSize);
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
0

If anyone is still looking for answer then: please note fileAttributesAtPath method is depriciated so use attributesOfItemAtPath method

Example:

//get full pathname of bundle directory
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];

//get paths of all of the contained subdirectories
NSArray *bundleArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:bundlePath error:nil];

//to access each object in array
NSEnumerator *filesEnumerator = [bundleArray objectEnumerator];

NSString *fileName;

unsigned long long int fileSize = 0;
NSError *error = nil;

//return next object from enumerator
while (fileName = [filesEnumerator nextObject])
{
    NSDictionary *fileDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:[bundlePath stringByAppendingPathComponent:fileName] error:&error];

    fileSize += [fileDictionary fileSize];
}
//converts a byte count value into a textual representation that is formatted with the appropriate byte modifier (KB, MB, GB and so on)
NSString *folderSizeStr = [NSByteCountFormatter stringFromByteCount:fileSize countStyle:NSByteCountFormatterCountStyleMemory];
NSLog(@"App size (bundle size): %@ \n\n\n",folderSizeStr);
1218GG
  • 393
  • 3
  • 11
0

Swift Answer - SWIFT 3.x

let bundlePath = Bundle.main.bundlePath
let bundleArray  = FileManager.default.subpaths(atPath: bundlePath)
var fileSize : UInt64 = 0
for file in bundleArray! {
    do {
        let attr = try FileManager.default.attributesOfItem(atPath: bundlePath + "/" + file )
        let xfileSize = attr[FileAttributeKey.size] as? UInt64 ?? 0
        fileSize =  fileSize + xfileSize
    } catch {
    }
}
let folderSize = ByteCountFormatter.string(fromByteCount: Int64(fileSize), countStyle: .memory)
print("App size (bundle size): \(folderSize)")//xx MB

Which will gives you app size in bundle -

/Users/MyLaptop/Library/Developer/CoreSimulator/Devices/DB7032C9-7CE2-42A9-83D1-59E2D2C5C361/data/Containers/Bundle/Application/CC808040-2F18-4B35-A912-591BD0C7DCD9/MyApp.app

Jack
  • 13,571
  • 6
  • 76
  • 98