Reputation: 23
No matter what I do, I can't seem to access my Info.plist file in the root of my framework's folder. So far, my code looks like this:
private var Config: NSDictionary {
get {
if let config = NSBundle.mainBundle().pathForResource("Info", ofType: "plist") {
return NSDictionary(contentsOfFile: config)!
}
return Dictionary<String, AnyObject>()
}
}
This returns a null Dictionary
, as the if let config
statement doesn't pass. I have also tried:
private var Config: NSDictionary {
get {
if let config = NSBundle.mainBundle().infoDictionary {
return NSDictionary(contentsOfFile: config as! String)!
}
return Dictionary<String, AnyObject>()
}
}
This time, the if let
statement passes, but is a blank Dictionary
(0 key/value pairs).
I am using Xcode 7.2.1. Help an iOS newbie out! Thanks in advance. :)
Upvotes: 0
Views: 1129
Reputation: 23
Solved!
After doing a bit more research, I found that access plists, or resources in general for that matter, are different for Frameworks. So, I tried:
if let config = NSBundle(identifier: "Smoo.Framework")?.infoDictionary {
return NSDictionary(dictionary: config["Key"] as! NSDictionary)
}
("Smoo.Framework" being the name of the bundle my required plist is in)
And that works! Case closed. :)
Upvotes: 1