Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在swift中将当前视图控制器作为参数传递给函数_Swift - Fatal编程技术网

如何在swift中将当前视图控制器作为参数传递给函数

如何在swift中将当前视图控制器作为参数传递给函数,swift,Swift,我想将当前视图控制器作为一个参数传递,以便重用它的函数。我在CommonUtils类中定义了“commonFunction(currentController:UIViewController)”,但它抛出了一个错误 static func commonFunction(currentController:UIViewController, dictionary: Dictionary<String, Any>) { currentController.getDownloadUR

我想将当前视图控制器作为一个参数传递,以便重用它的函数。我在CommonUtils类中定义了“commonFunction(currentController:UIViewController)”,但它抛出了一个错误

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]))
}
错误详细信息:


  • “UIViewController”类型的值没有成员“getDownloadURL”

  • “UIViewController”类型的值没有成员“userDetails”

  • currentController:UIViewController
    是一个通用vc,它没有您调用的方法/属性
    getDownloadURL/userDetails
    您需要传递具有这些方法/属性的实际vc实例
    currentController:MyViewController


    或者创建一个所有实例都是其子类的超类vc,并在其中插入这些方法/属性

    你能粘贴错误吗?类型为“UIViewController”的值没有成员“getDownloadURL”类型为“UIViewController”的值没有成员“userDetails”很简单,您将UIViewController作为参数,但UIViewController类中没有此类变量。您应该传递子类类型,而不是
    UIViewController
    (例如
    MyCustomViewController
    ),但在许多控制器中使用相同的代码,因此我会将其设置为动态的