簡體   English   中英

從文檔目錄而不是捆綁包中獲取plist

[英]getting plist from documents directory instead of Bundle

我試圖指向文檔目錄而不是Bundle,我有以下代碼:

    - (id)initWithLibraryName:(NSString *)libraryName {
         if (self = [super init]) {
             libraryPlist = libraryName;
             libraryContent = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] 
                                        pathForResource:libraryPlist ofType:@"plist"]];

我知道我需要使用以下命令將應用程序指向文檔目錄:

      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];

我的問題是在上面的示例中該指針應插入哪里?

[[NSBundle mainBundle] pathForResource:libraryPlist ofType:@"plist"];

也是等效的:

[documentsDirectory stringByAppendingPathComponent:[libraryPlist stringByAppendingPathExtension:@"plist"]];

如果文件不存在,則bundle調用將返回nil。 您可以在NSFileManager中使用fileExistsAtPath:來檢查文件是否存在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM