2013-04-05 71 views
0

嗨,我是新的目标c。从保存的plist文件中检索URL

我将我的URL数据保存在资源下的plist文件中。这是我的代码。

NSString *plistPath =[[[NSBundle mainBundle] resourcePath] 
      stringByAppendingPathComponent:@"myfile.plist"]; 

NSDictionary *plistDict = [[NSUserDefaults standardUserDefaults] 
             dictionaryRepresentation]; 

if([plistDict writeToFile:plistPath atomically:YES]) { 
    NSLog(@"success"); 
} else { 
    NSLog(@"error"); 
} 

现在我想从保存的plist(我file.plist),我怎样才能检索到,我可以使用该URL的Web视图获取URL。

e.g:

urlString.stringValue = ???? 

这里我使用urlString.stringValue的网页流量。

[[webview mainFrame] loadRequest:[NSURLRequest requestWithURL: 
       [NSURL URLWithString:urlString.stringValue]]]; 

感谢

回答

0

首先,你并不需要保存NSUserDefaults的对自己的文件。其内容会定期自动保存,或者您可以拨打synchronize立即保存。

但是,如果要将字典保存为plist,请使用现有的writeToFile:atomically:方法。然后你可以通过创建一个新的字典与plist的内容再次加载它:

[NSDictionary dictionaryWithContentsOfFile:plistPath]; 
+0

非常感谢,它帮助了我。 – fazal 2013-04-05 14:53:24