import Foundation
import PlaygroundSupport
let path = playgroundSharedDataDirectory.appendingPathComponent("input.plist")
let nsArray = try NSArray(contentsOf: path, error: ())
var item0 = nsArray[0]
var test = (item0 as! NSDictionary)["AKey"]
print(test)
The only thing I added except fixing the code you posted is type casting to NSDictionary
P.S. don't use as! in a real project, it's better to gracefully handle the errors
My mistake was trying to coerce type into a Dictionary, and not to a NSDictionary, getting cryptic error message.
I still have a lot to learn before handling gracefully errors...
FYI, it is probably more elegant to parse the property list using PropertyListDecoder. Look up the documentation for Codable for more information on how to do it.
I figured so also, but since my .pfile has irregularities (no same keys, arrays in value,...) I needed to fix first my type casting errors, before assimilating PropertyListDecoder.
Thanks for confirming the hint.
You can still use Codable in these cases, but you'll need to do some more custom handling compared to just writing types. If you can share a full sample plist, we can step through the necessary code. The end result will probably be cleaner than messing around with NS-typecasting stuff.
Actually, I am trying to clean up my Mail.app rules that are now a 5500 lines file with all the mail adresses I want to direct to specific mail boxes, that have been accumulated for a decade or two. So the plist file is the syncedRules.plist that can be found in Library/Mail/V7/SyncedRules.plist.
It's an array of rules, each rule being a dict of keys, with one being for criteria used, itself being a array of conditions, each condition a dictionary where you can find domain names. The (sofar) vague idea is to identify which domain names conditions are redundants (can be performed automatically), and maybe also obsolete (with a manual glance).
The objective is to accelerate the everyday filtering, but also to make my first real swift program :)