来自NSData的文件路径

Jac*_*nkr 1 cocoa nsdata ios

我有一个NSData,我正在从filePath加载.然后数据被传递,我需要filePath来获取数据的来源.

除了将filePath作为额外参数传递之外,最简单的方法是什么?

joe*_*ick 5

将两者都包装在表示文件的容器对象中,例如

@interface File : NSObject

@property (strong) NSData *fileContents;
@property (copy) NSString *filePath;

// perhaps, even a nice constructor to fill these properties
- (id)initWithFilePath:(NSString *)filePath;

@end
Run Code Online (Sandbox Code Playgroud)