Nadav
Nadav

Reputation: 2717

iOS Framework - get plist into a dictionary

I am creating an iOS - framework (swift) I have this function - which I am using for retrieving a dictionary that should hold all of the lib properties (strings)

func getPropertyList() -> [String: Any]?{
    let path = Bundle.main.path(forResource: "properties", ofType: "plist")!
    let dict = NSDictionary(contentsOfFile: path) as? [String: Any]
    return dict
}

from test this line keep returning nil

Bundle.main.path(forResource: "properties", ofType: "plist")!

even though the properties.plist file is inside the 'copy Bundle Resources' and the target membership is selected

enter image description here

enter image description here

Upvotes: 1

Views: 405

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

Use

let path = Bundle(identifier:"com.example.frameworkID")!.path(forResource: "properties", ofType: "plist")!

Upvotes: 3

Related Questions