forked from danielamitay/iOS-App-Performance-Cheatsheet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6491637
commit fc674fc
Showing
2 changed files
with
25 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters