Swift 3 init - 意外错误

标签 swift oop swift3 xcode8

在我认为是一个简单的子类中,我似乎不太明白这个问题。

此错误消息有任何意义吗?

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

enter image description here

或者,

enter image description here

SKPhoto 已声明开放,以下是父类(super class)的可用初始化:

// 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
    }

我实在无法解决这个问题!

最佳答案

SKPhoto 类似乎有问题;它尚未开放其 init 方法,因此您无法在子类中重写它们;

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

如果您确实想使用它,您应该 fork 该存储库并进行适当的更改,然后就可以使用它。

关于Swift 3 init - 意外错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40366321/

相关文章:

ios - 将文本字段限制为一位小数点输入,仅限数字,以及小数点后两个字符 - Swift 3

ios - 如何在collectionView中嵌入一些具有不同数据的tableView?

c# - 访问子类中的私有(private)变量?

c# - 始终具有参数化构造函数的类

python - 如何只获取父类对象的属性

ios - swift 3/ Alamofire 4 : Fetching data with the ID on a TableView

swift - 在 Swift 中使用 MPMoviePlayerController() 播放 MP4

swift - 如何以编程方式创建 UIButton

ios - 为什么我在 Swift 中收不到来自 Firebase 的推送通知?

ios - 为什么文件名会在 alamo fire 在 swift 3 中上传图像时返回 nil?