如何从另一个 class 访问 ViewController 的 class 功能?

How to access ViewController's class functions from another class?

我在ViewControllerclass中有这个功能:

func detect(image: CIImage) {
    guard let model = try? VNCoreMLModel(for: Resnet50().model)
        else {
            fatalError("Loading CoreML Model Failed.")
    }

    let request = VNCoreMLRequest(model: model) {
        (request, error) in
        guard let result = request.results as? [VNClassificationObservation]
            else {
                fatalError("Model failed to process image.")
        }
        print(result.first?.identifier as Any)
        self.imageLabel.text = result.first?.identifier
    }

    let handler = VNImageRequestHandler(ciImage: image)
    do {
        try handler.perform([request])
    } catch {
        print(error)
    }
}

我正在尝试使用 result.first?.identifier 在另一个名为 SecondViewController:

的 class 中做类似的事情
if(result.first?.identifier == "flowers") {
    self.infoLabel.text = "info about flowers"
}

但我不知道如何访问另一个 class 中的函数。我刚开始编码 Swift。

我发现 a link 帮助我解决了我遇到的这个问题,如果以后有人需要,我会在这里分享。