Skip to content

Instantly share code, notes, and snippets.

@keremvatandas
Last active February 19, 2019 18:52
Show Gist options
  • Save keremvatandas/83192f90733c6de578d41ef0e6108b21 to your computer and use it in GitHub Desktop.
Save keremvatandas/83192f90733c6de578d41ef0e6108b21 to your computer and use it in GitHub Desktop.

Revisions

  1. keremvatandas revised this gist Feb 19, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion any.swift
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,6 @@ class User {
    }



    var anyType: Any
    anyType = User(name: "Kerem", age: 28, favProgLang: "Lisp")
    anyType.display() // Value of type 'Any' has no member 'display'
  2. keremvatandas created this gist Feb 19, 2019.
    27 changes: 27 additions & 0 deletions any.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    class User {
    var name: String
    var age: Int
    var favProgLang: String

    init(name: String, age: Int, favProgLang: String){
    self.name = name
    self.age = age
    self.favProgLang = favProgLang
    }

    func display(){
    print("Isim -> \(self.name)\nYas -> \(self.age)\nFavori Programlama Dili -> \(self.favProgLang)")
    }
    }



    var anyType: Any
    anyType = User(name: "Kerem", age: 28, favProgLang: "Lisp")
    anyType.display() // Value of type 'Any' has no member 'display'


    var anyType: Any
    anyType = User(name: "Kerem", age: 28, favProgLang: "Lisp")
    var res = anyType as! User
    res.display()