Wednesday, October 28, 2026
HomeiOS Developmentios - why cannot i declare comfort UIImage return non-nil in swift...

ios – why cannot i declare comfort UIImage return non-nil in swift like this?

[ad_1]

extension UIImage {
    comfort init(nonnil: String) {
        self.init(named:nonnil) ?? UIImage(systemName: "")!
// or        self.init(named:nonnil) ?? self.init(named:"")! 
  }
}

i would like the UIImage constructor to not be nil , so i kind ?? to return if the entrance is nil and the again is forceUnwrap (swift-error ‘Can not convert worth of kind ‘UIImage’ to anticipated argument kind ‘()’)

p/s; i attempted some ways and nonetheless not accepted by compiler, i’ve to make use of static or nullable init and have to make use of non-obligatory,

— Seems swift isn’t as sensible as I assumed, hopefully model 6 will enhance this – (As a result of I simply switched to Swift)

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments