Advertisement
Guest User

Navigation handle

a guest
Jul 16th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.67 KB | None | 0 0
  1.  
  2.   func camelFirst() -> String? {
  3.         let item = self.matchingStrings(regex: "[^A-Z]+")
  4.         if item.count > 0 {
  5.             if item[0].count > 0 {
  6.                 return item[0][0]
  7.             }
  8.             else { return nil }
  9.         }
  10.         else {
  11.             return nil
  12.         }
  13.     }
  14.  
  15.  
  16.  
  17. class func openStoryboardId(_ caller: UIViewController, id: String) -> UIViewController? {
  18.         if let name = id.camelFirst() {
  19.             if let currentID = caller.restorationIdentifier {
  20.                 if let current = currentID.camelFirst() {
  21.                     if current == name {
  22.                         return caller.storyboard?.instantiateViewController(withIdentifier: id)
  23.                     }
  24.                     else {
  25.                         let storyboard = UIStoryboard(name: name.capitalized, bundle: nil)
  26.                         return storyboard.instantiateViewController(withIdentifier: id)
  27.                     }
  28.                 }
  29.                 else {
  30.                     let storyboard = UIStoryboard(name: name.capitalized, bundle: nil)
  31.                     return storyboard.instantiateViewController(withIdentifier: id)
  32.                 }
  33.             }
  34.             else {
  35.                 let storyboard = UIStoryboard(name: name.capitalized, bundle: nil)
  36.                 return storyboard.instantiateViewController(withIdentifier: id)
  37.             }
  38.         }
  39.         else {
  40.             return nil
  41.         }
  42.     }
  43.  
  44.  
  45.   func openOtherView() {
  46.         if let viewController = DTUI.openStoryboardId(self, id: "settingSettings") {
  47.             self.navigationController?.pushViewController(viewController, animated: true)
  48.         }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement