I have a real problem trying to get to grips with the whole Optionals/wrapping thing, and associated type issues.
Here's my code:
import Quartz
import Foundation
func listFilters() -> Void {
let theFilters = QuartzFilterManager.filters(inDomains: nil)!
for eachFilter in theFilters as! [QuartzFilter] {
print(eachFilter.localizedName()!, ":", eachFilter.url().path)
}
}
listFilters()
So, in the first line of the function, I have to explicitly force unwrap the result of the method that returns a list of QuartzFilters. (Why?)
The very next line, I have to force them to be of type QuartzFilters, (because why wouldn't the method return the actual type of thing that they are?)
And then on the third line, I still have to force unwrap one of the properties of something that I've already unwrapped (otherwise I get optionals), but not the other one.
Yes, I understand it's all about trying to prevent a null condition, but nearly everything is never null.
Even if I use if let
on the first line, I'm still unwrapping stuff inside that if
.