Can You help me with this Error?

Hey, I just started making an App with XCode, that should be an Extension for a Game, that I play with my Friends. I started programming it (I watched many tutorials), but now I get this Error. After trying two hours to fix it, I found this Forum.


Here is my code from the NamenEintragenViewController.swift-File:

import UIKit

class NamenEintragenViewController: UIViewController {

    @IBOutlet weak var TextFieldPlayer1: UITextField!
    @IBOutlet weak var TextFieldPlayer2: UITextField!
    @IBOutlet weak var TextFieldPlayer3: UITextField!
    @IBOutlet weak var TextFieldPlayer4: UITextField!
    @IBOutlet weak var TextFieldPlayer5: UITextField!
    @IBOutlet weak var TextFieldPlayer6: UITextField!
    @IBOutlet weak var NextButton: UIButton!
    
    var namen: Namen?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.namen = Namen()
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        self.namen?.player1 = TextFieldPlayer1.text
        
        let windVC = segue.destination as! WindstossViewController
        windVC.namen = self.namen
    }

And here the one from the WindstossViewController-File:

import UIKit

class WindstossViewController: UIViewController {

    @IBOutlet weak var WindstossLabel: UILabel!
    @IBOutlet weak var WindstossPerson: UILabel!
    
    var namen: Namen?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.WindstossPerson.text = "\(namen!.player1 ?? "Fehler")"
    }
}

This is the Error I get:

2019-03-02 14:50:16.044096+0100 Schlamperich[41861:1587101] libMobileGestalt MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.
2019-03-02 14:50:19.605328+0100 Schlamperich[41861:1587101] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/erikhaarlander/Library/Developer/CoreSimulator/Devices/6CD501B8-ADD3-474D-A689-8C1B85CD1FA9/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2019-03-02 14:50:19.654877+0100 Schlamperich[41861:1587101] [MC] Reading from private effective user settings.
Could not cast value of type 'Schlamperich.SchlamperichErwachtViewController' (0x109aaf208) to 'Schlamperich.WindstossViewController' (0x109aaf008).
2019-03-02 14:50:24.351602+0100 Schlamperich[41861:1587101] Could not cast value of type 'Schlamperich.SchlamperichErwachtViewController' (0x109aaf208) to 'Schlamperich.WindstossViewController' (0x109aaf008).
(lldb)

Can You please Help Me fixing this?

Thank You


Regards

DerBerliner

Replies

> making an App with XCode


Which version?


Did you search on that error?


Example, prevous thread:

https://forums.developer.apple.com/thread/103753


Ref.:For Best Results - Read the Label

You have an error when trying to cast a type:


SchlamperichErwachtViewController' (0x109aaf208) to 'Schlamperich.WindstossViewController' (0x109aaf008).


That could be line 23

        let windVC = segue.destination as! WindstossViewController

Where do you segue ? I mean, what is the type of controller you try to segue to ? Probably, it is not a WindstossViewController. So check your segue carefully.


A general comment: in Swify, the names of instances, var,, constant… should use caleCase, so start with lowercase. Uppercase is reserved for classes, struct…


So, change the names of your IBOutlets (in fact use Refactor > Rename to do this, by cmd-click on the name you want to change)

    @IBOutlet weak var textFieldPlayer1: UITextField! 
    @IBOutlet weak var textFieldPlayer2: UITextField! 
    @IBOutlet weak var textFieldPlayer3: UITextField! 
    @IBOutlet weak var textFieldPlayer4: UITextField! 
    @IBOutlet weak var textFieldPlayer5: UITextField! 
    @IBOutlet weak var textFieldPlayer6: UITextField! 
    @IBOutlet weak var nextButton: UIButton!