achi achi - 1 month ago 6
Swift Question

Swift 3 init - unexpected error

In what I thought was to be a simple subclass, I can't quite seem to figure out the issue.

Does this error message make any sense?

'super.init' cannot be called outside of an initializer


enter image description here

Alternatively,

enter image description here

SKPhoto is declared open, and here are the available inits of the superclass:

// MARK: - SKPhoto
open class SKPhoto: NSObject, SKPhotoProtocol {

open var underlyingImage: UIImage!
open var photoURL: String!
open var contentMode: UIViewContentMode = .scaleAspectFill
open var shouldCachePhotoURLImage: Bool = false
open var caption: String!
open var index: Int = 0

override init() {
super.init()
}

convenience init(image: UIImage) {
self.init()
underlyingImage = image
}

convenience init(url: String) {
self.init()
photoURL = url
}

convenience init(url: String, holder: UIImage?) {
self.init()
photoURL = url
underlyingImage = holder
}


I embarassingly can't solve this problem!

Answer

There seems to be a problem in the SKPhoto class; it has not made its init methods open so you can not override them in your sub class;

https://github.com/suzuki-0000/SKPhotoBrowser/blob/swift3/SKPhotoBrowser/SKPhoto.swift

If you really want to use it, you should fork the repo and make appropriate changes, then may use it.

Comments