ios - Swift Type Variable for conditional optional unwrapping -


i trying set type variable , use conditionally unwrap optional. here example:

func testint() {     var test:int? = 15      let inttype = int.self      if let testint = test as? inttype {         print("is int")     } else {         print("not int")     } } 

in example above error of 'inttype' not type.

is possible do?

i have tried .type , same error.

edit****

here example of trying do. above example meant simple example of storing type in variable. understand there other ways accomplish function above does...

class tablecell0: uitableviewcell {} class tablecell1: uitableviewcell {}  enum sectioninfo: int {     case section0 = 0, section1      var cellidentifier: string {         let identifiers = ["section0cell", "section1cell"]         return identifiers[self.rawvalue]     }      var celltype: uitableviewcell.type {         let types:[uitableviewcell.type] = [tablecell0.self, tablecell1.self]         return types[self.rawvalue]     } }  override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {      guard let sectioninfo = sectioninfo(rawvalue: indexpath.section) else {         fatalerror("unexpected section passed tableview")     }      guard let cell = tableview.dequeuereusablecellwithidentifier(sectioninfo.cellidentifier, forindexpath: indexpath) as? sectioninfo.celltype else {         fatalerror("unexpected cell dequeued tableview")     }     return cell } 

this should create correct type of cell want

i think understand trying do. use dynamictype compare it, rather conditionally unwrapping optional.

func testint() {     var test:int = 15     let inttype = int.self      if test.dynamictype == inttype {         print("is int")     } else {         print("not int")     } } 

at least work integer example, not sure if work uitableviewcell example or not.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -