It's been about years since I've done any work in macOS and more than two since I've touched Swift. I'm running myself in circles on this:
I have two functions, the first contains a while loop to check the value within a dictionary returned by the second. :
func checkPath(_ strPath:String) {
...
while bIsDesktop == false {
let dictResults:Dictionary<String, Any> = checkPath(arrPath)
if dictResults["isDesktop"] { //-->I'm getting crushed here
//do something with returned array
}
}
private func checkPath(_ arrPath:Array<String>) -> Dictionary<String, Any> {
var bIsDesktop = false
var arrPath = arrPath
if arrPath[0] != "Desktop" {
arrPath.removeFirst()
} else {
bIsDesktop = true
}
return ["paths":arrPath, "isDesktop":bIsDesktop]
}
arrPath is an array of strings (file path items)
I know the returned dictionary is like so [String:Any]
Problem is no matter what I do I run into some sort of compiler error like:
Optional type 'Any?' cannot be used as a boolean; test for '!= nil' instead
In the grander scheme of things, in case there's a more elegant solution, what I am trying to do is strip the path to a folder selected by the user of the ///File:User/username/Desktop/... and just have Desktop/... If there's a better solution than what I am attempting I'd appreciate seeing it but if you could also explain why I can't get the optional out of the dictionary I'd appreciate that as well.
I've tried:
guard let bIsDesktop = dictResults["isDesktop" as Bool else { ...
if dictResults?["isDesktop"]...
and various other permutations. Either I get nil or a compiler error.