如何在类中具有初始化程序,但仍能够访问该类的值 [英] How to have initializers in a class but still be able to access the class's values
本文介绍了如何在类中具有初始化程序,但仍能够访问该类的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个函数,只需要访问具有初始化程序的对象内的一个值即可。
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:
不能在没有参数的情况下调用'Media'类型的初始化程序
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?
推荐答案
要做的所有事情就是声明一个有任何参数的init:
All that needs to be done is to declare a init withough any paramaters:
class Media: NSObject {
override init() { }
}
这篇关于如何在类中具有初始化程序,但仍能够访问该类的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文