ios - Dynamic Type in Swift 3 -


i've migrated swift version 2.3 3 , converted code automatically, below case on i'm getting crash i've tried options in vain,

swift 2.3:works fine

public func huntsuperviewwithclassname(classname: string) -> uiview? {     var foundview: uiview? = nil      var currentveiw:uiview? = self      while currentveiw?.superview != nil{         if let classstring = string.fromcstring(class_getname(currentveiw?.dynamictype)){              if let classnamewithoutpackage = classstring.componentsseparatedbystring(".").last{                 print(classnamewithoutpackage)                 if classnamewithoutpackage == classname{                     foundview = currentveiw                     break                 }             }         }         currentveiw = currentveiw?.superview     }      return foundview } 

}

swift 3:not fine

  if let classstring = string(validatingutf8: class_getname(type(of:currentveiw) as! anyclass)) { 

tried line too:

  if let classstring = string(describing: class_getname(type(of: currentveiw) as! anyclass)){ 

but doesn't work..

please guide me how correct line according swift 3:

 if let classstring = string.fromcstring(class_getname(currentveiw?.dynamictype)){ 

the compiler telling you can't use if let because it's totally unnecessary. don't have optionals unwrap.if let used exclusively unwrap optionals.

public func huntsuperviewwithclassname(classname: string) -> uiview? {     var foundview: uiview? = nil      var currentveiw:uiview? = self      while currentveiw?.superview != nil{              let classstring = nsstringfromclass((currentveiw?.classforcoder)!)              if let classnamewithoutpackage = classstring.components(separatedby:".").last{                 print(classnamewithoutpackage)                 if classnamewithoutpackage == classname{                     foundview = currentveiw                     break                 }             }         }         currentveiw = currentveiw?.superview     }      return foundview } 

works fine!


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -