How to create an empty variable that can take the type of a class value

Hey, I'm trying to figure out how to set a variable to an empty class type. For example, if this is not an error:

the code:

  var PlayerEquipped = class() // failed attempt at trying set up a blank variable that can take the type of a class

Or make a variable that I can change in the future. Therefore, in principle, I can create a global variable like this with the class assigned to it without any problems.

the code:

   var PlayerEquipped = House()

          //In another .swift file i have the 2 classes

    class House {
    init() {
     }
    }

    class House2 {
    init() {
     }
    }

, "var" , "SelectClass" . , "Hello" in-side, "GoddBye", . "SelectedClass" , . : " saintsRB saintsLB ' :

      var PlayerEquipped = House()

   //down in view didload:
       PlayerEquipped = House2() // Error here

Error image

+4
2

var PlayerEquipped: AnyObject

var PlayerEquipped: AnyObject?
+5

, :

  • (, Buildable). . Buildable (, var house:Buildable? - ?, , nil). ,

  • (, House). (House1, House2 ..) House. House (, var house:House?)

Any AnyObject , , , , .

, , .

+2

Source: https://habr.com/ru/post/1653579/


All Articles