如何在swift中将当前视图控制器作为参数传递给函数
我想将当前视图控制器作为一个参数传递,以便重用它的函数。我在CommonUtils类中定义了“commonFunction(currentController:UIViewController)”,但它抛出了一个错误如何在swift中将当前视图控制器作为参数传递给函数,swift,Swift,我想将当前视图控制器作为一个参数传递,以便重用它的函数。我在CommonUtils类中定义了“commonFunction(currentController:UIViewController)”,但它抛出了一个错误 static func commonFunction(currentController:UIViewController, dictionary: Dictionary<String, Any>) { currentController.getDownloadUR
static func commonFunction(currentController:UIViewController, dictionary: Dictionary<String, Any>) {
currentController.getDownloadURL(email: String.getString(currentController.userDetails[JsonKeys.Kemail]),orgId: String.getString(currentController.userDetails[JsonKeys.KorganizationId]), fileId: Int.getInt(dictionary[JsonKeys.KtypeId]))
}
static func commonFunction(currentController:UIViewController,dictionary:dictionary){
currentController.getDownloadURL(电子邮件:String.getString(currentController.userDetails[JsonKeys.Kemail]),orgId:String.getString(currentController.userDetails[JsonKeys.KorOrganizationId]),fileId:Int.getInt(字典[JsonKeys.KtypeId]))
}
错误详细信息:
此
currentController:UIViewController
是一个通用vc,它没有您调用的方法/属性getDownloadURL/userDetails
您需要传递具有这些方法/属性的实际vc实例currentController:MyViewController
或者创建一个所有实例都是其子类的超类vc,并在其中插入这些方法/属性你能粘贴错误吗?类型为“UIViewController”的值没有成员“getDownloadURL”类型为“UIViewController”的值没有成员“userDetails”很简单,您将UIViewController作为参数,但UIViewController类中没有此类变量。您应该传递子类类型,而不是
UIViewController
(例如MyCustomViewController
),但在许多控制器中使用相同的代码,因此我会将其设置为动态的