How to have initializers in a class but still be able to access the class's values

╄→尐↘猪︶ㄣ 提交于 2020-01-06 05:16:08

问题


I have a function that only needs to access one value inside an object with has initializers.

ImageUploadManager().sendImages(self.images, postID: postID, image: Media().postImage)

However doing so yields the following error:

Cannot invoke initializer for type 'Media' with no arguments

So my question is: is it possible to access a value as I do here withought having to initialize?


回答1:


All that needs to be done is to declare a init withough any paramaters:

    class Media: NSObject {

    override init() { }
}


来源:https://stackoverflow.com/questions/53234459/how-to-have-initializers-in-a-class-but-still-be-able-to-access-the-classs-valu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!