Swift unable to locate and read property list (.plist) file
Normally, this is what you do:
In the Project Navigator (on the left), select the plist file. In the File Inspector (on the right), examine the target membership settings. You will probably find that the app target is not checked. This means that the plist file is not being copied into the app bundle when you build it. Check the app target, and all will be well.
But you can't do that, because this is a command line program. It is an executable and no more. There is no bundle to copy into. What you're trying to do is metaphysically impossible. /p>
Swift 5: How to read variables in plist files?
Your property list format is not very convenient. As you want an array anyway create the property list with an array for key animals
(and name all keys lowercased)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>animals</key>
<array>
<dict>
<key>name</key>
<string>Tiger</string>
<key>picture</key>
<string>tiger_running</string>
</dict>
<dict>
<key>name</key>
<string>Jaguar</string>
<key>picture</key>
<string>jaguar_sleeping</string>
</dict>
</array>
</dict>
</plist>
Then create two structs
struct Root : Decodable {
let animals : [Animal]
}
struct Animal : Decodable {
let name, picture : String
}
and the data source array
var animals = [Animal]()
And decode the stuff
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let url = Bundle.main.url(forResource: "Animals", withExtension:"plist")!
do {
let data = try Data(contentsOf: url)
let result = try PropertyListDecoder().decode(Root.self, from: data)
self.animals = result.animals
} catch { print(error) }
}
PropertyListDecoder
and PropertyListSerialization
are state of the art in Swift. The NSDictionary/NSArray
API is objective-c-ish and outdated.
error: unable to read input file as a property list: The operation couldn’t be completed. (XCBUtil.PropertyListConversionError error 1.)
I have been facing the same problem with a newly imported Flutter project.
After some debugging, it seems like the issue was caused by a corrupt GoogleService-Info.plist
file! Dunno why and how it was corrupted, because I have newly imported and existing project.
To solve this problem, you can follow those steps;
- Open your project in XCode
- delete the existing
GoogleService-Info.plist
file - download the original one from Firebase
- then reimport/re-copy this file into your project
When this is done,
run flutter clean
then try running it in iOS Simulator
This worked for me, hope it solves your problem too.
Failed to open property list: Found non-key inside dict at line 44
You have:
<key>NSPhotoLibraryUsageDescription</key>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
You have two consecutive keys, and the value for NSPhotoLibraryUsageDescription
is expected to be a String, to next line after <key>NSPhotoLibraryUsageDescription</key>
should be <string>some text</string>
So change it:
<key>NSPhotoLibraryUsageDescription</key>
<string>Explain why user should allow to your app to access Photo Library</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
Where is Info.plist in Xcode 13? (missing, not inside project navigator)
It's a "feature."
You don't need it anymore. From the Release Notes:
Projects created from several templates no longer require configuration files such as entitlements and Info.plist files. Configure common fields in the target’s Info tab, and build settings in the project editor. These files are added to the project when additional fields are used. (68254857)
So, instead of inside Info.plist
, edit properties like NSCameraUsageDescription
here:
Project -> Targets -> Info -> Custom iOS Target Properties
The first time you add/edit, Xcode will automatically generate a new Info.plist
file that’s kind of synced1 with Custom iOS Target Properties
. Xcode will later merge them for you.
[1]: They’re not fully synced. Some properties like NSCameraUsageDescription
will only appear in Custom iOS Target Properties, while Application requires iPhone environment
will appear in both. I have no idea how Xcode determines this.
Want Info.plist
back, completely?
You might want all of your app's properties in one place. Or maybe you don't trust Xcode with the merging. I spoke with an Apple engineer at WWDC21 about this... here's how to get the classic Info.plist
back.
- Create a new "Property List" file (File -> New -> File)
- Name it
Info.plist
- Copy and paste the existing values from
Project -> Targets -> Info -> Custom iOS Target Properties
toInfo.plist
.
Copy | Paste |
---|---|
Info.plist Utility Error: Info.plist couldn't be opened because there is no such file
The solution for this particular instance of the error was “Info.plist couldn't be opened because there is no such file” was that I had deleted all of the files in the "Project Tests" folder, but was still had "Project Tests" listed under my targets. After deleting the "tests" target, the project built successfully.
Related Topics
Move Button When Keyboard Appears Swift
Is There Any Difference at All Between Suffix(From:) and Dropfirst(_:)
Cannot Convert Value of Type 'X' to Expected Argument Type 'X'
Which Optimization Level Should I Choose for Release
A Concise Way to Not Execute a Loop Now That C-Style for Loops Are Going to Be Removed from Swift 3
Performseguewithidentifier Not Working If Called from Viewdidload
Cmlogitem Timestamp: Why So Complicated
Count Number of Instances of a Class Swift
How to Cast Sockaddr_In to Sockaddr in Swift
Sknode Subclass Generates Error: Cannot Invoke Initializer for Type "X" with No Arguments
How to Get The Count of a Type Conforming to 'sequence'
Why I Can Not Use Setvalue for Dictionary
How to Define a Variable in a Swift If Statement
Nsjsonserialization Error. Code=3840 "Invalid Value Around Character 0
Nsdatepicker in Nsstatusbar Nssmenuitem Not Receiving Input
Custom Radix Columns (+Special Characters)