Skip to content

Commit

Permalink
Add NSFileManager entry
Browse files Browse the repository at this point in the history
  • Loading branch information
danielamitay committed Oct 20, 2013
1 parent 6491637 commit fc674fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 21 additions & 0 deletions Foundation.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# Foundation

- [NSFileManager](#nsfilemanager)

---

### NSFileManager

#####- (NSDictionary *)attributesOfItemAtPath:(NSString *)filePath error:(NSError *)error

When attempting to retrieve an attribute of a file on disk, using `–[NSFileManager attributesOfItemAtPath:error:]` will expend an excessive amount of time fetching additional attributes of the file that you may not need. Instead of using `NSFileManager`, you can directly query the file properties using `stat`:

```objective-c
//#import <sys/stat.h>

struct stat statbuf;
const char *cpath = [filePath fileSystemRepresentation];
if (cpath && stat(cpath, &statbuf) == 0) {
NSNumber *fileSize = [NSNumber numberWithUnsignedLongLong:statbuf.st_size];
NSDate *modificationDate = [NSDate dateWithTimeIntervalSince1970:statbuf.st_mtime];
NSDate *creationDate = [NSDate dateWithTimeIntervalSince1970:statbuf.st_ctime];
// etc
}
```
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ Most code substitutions documented here consist of replacing high-level APIs tha
### Table of Contents

**iOS App Performance Cheatsheet** is sectioned into Markdown files by Objective-C framework:
- [Foundation](Foundation.md)
- [UIKit](UIKit.md)
- [QuartzCore](QuartzCore.md)
- [**Foundation**](Foundation.md)
- [NSFileManager](Foundation.md#nsfilemanager)
- [**UIKit**](UIKit.md)
- [**QuartzCore**](QuartzCore.md)

### Why is this on GitHub?

Expand Down

0 comments on commit fc674fc

Please sign in to comment.