How to transfer content from one Viewcontroller variable to another

Asked

Viewed 62 times

0

Excuse my ignorance of beginner programmer. I followed the tips above but it makes a mistake when I do the self:

Cannot assign value of type "Telaprincipalviecontroller" to type "Telaajustesviewcontroller".

TelaAjustesViewController is the Screen 1 of his example and the TelaPrincipalViewController is the 2.
The value that comes from Screen 1, is the content of Cor.

import UIKit

class TelaPrincipalViewController: UIViewController { var TransfereCor:TelaAjustesViewController!

override func viewDidLoad()
{
    let v2 = TelaPrincipalViewController ()
    v2.TransfereCor = self
    switch TransfereCor.Cor
    {
    case 0:
        print("Escuro")
        break
    case 1:
        print("Claro")
        break
    case 2:
        print("Daltônico")
        break
    default:
        break
    }
    print(TransfereCor.Cor)

1 answer

0

You have to instantiate the previous screen:

var Transferecor:Telaajustesviewcontroller = Telaajustesviewcontroller()

Then you will be able to pick up her attributes through Transferecor.Cor

Browser other questions tagged

You are not signed in. Login or sign up in order to post.