Search code examples
iosswiftsegue

I am unable to perform segue from a view controller to another view controller using a class (by creating an instance)


class Codemanager {
    static let instance = Codemanager()
    public var codevc : CodeVC?
    func compile_snippet(inputs : String,language : String, content: String) -> String{
        Alamofire.request(apilink, method: .post, parameters: body , encoding: JSONEncoding.default, headers: headers).responseJSON
                {(response) in
                        guard let data = response.data else { return }
                        do{
                            let json = try JSON(data: data)
                            print(json)
                            outputcode = json["stdout"].stringValue + "\n" + json["stderr"].stringValue + "\n" + json["error"].stringValue
                            self.codevc?.gotooutputscreen()  //gotooutputscreen() is a function of CodeVC
                        }
                        catch{
                            debugPrint(error)
                        }
            }
            return outputcode
        }  
    }
}

My CodeVC code is as follow :-

public func gotooutputscreen()
{
    performSegue(withIdentifier: "tooutputscreen", sender: nil)
}

I can't able to make out the way to perform segue from a class.


Solution

  • You have to make sure codevc contains a non-nil value

    Codemanager.instance.codevc = self