Initiating Child ViewController from UIStoryBoard in iOS











up vote
0
down vote

favorite












I'm trying to use inheritance in UIViewController where base class has XIB in storyboard. I'm troubling with initiating different children classes with that XIB.

I cannot use XIB file separately instead of storyboard because it has static UITableViewCells.



So here is how I'm managing it currently using object_setClass method in SWIFT:
Parent Class:



class MeetingViewController: UITableViewController {

private(set) var project: CDProject?
private(set) var meeting: CDMeeting?

static func initWith(project: CDProject?, meeting: CDMeeting?) -> MeetingViewController {
let storyboard = UIStoryboard(name: "Meeting", bundle: nil)
let meetingVC = storyboard.instantiateViewController(withIdentifier: "MeetingVCId") as! MeetingViewController
meetingVC.project = project
meetingVC.meeting = meeting
return meetingVC
}
}


Child Class-1:



class MeetingInfoViewController: MeetingViewController {

static func initWith(meeting: CDMeeting) -> MeetingInfoViewController {
let meetingVC = MeetingViewController.initWith(project: nil, meeting: meeting)
object_setClass(meetingVC, MeetingInfoViewController.self)
return meetingVC as! MeetingInfoViewController
}
}


Child Class-2:



class MeetingCreateViewController: MeetingViewController {

static func initWith(project: CDProject) -> MeetingCreateViewController {
let meetingVC = MeetingViewController.initWith(project: project, meeting: nil)
object_setClass(meetingVC, MeetingCreateViewController.self)
return meetingVC as! MeetingCreateViewController
}
}


This is working very fine, not any issue; but I'm just curious if:

1 there's any other way to handle this scenario?

2 this approach has any side-effects?

3 this can be improved somehow?



Also feel free to point out other things than initialisation!










share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm trying to use inheritance in UIViewController where base class has XIB in storyboard. I'm troubling with initiating different children classes with that XIB.

    I cannot use XIB file separately instead of storyboard because it has static UITableViewCells.



    So here is how I'm managing it currently using object_setClass method in SWIFT:
    Parent Class:



    class MeetingViewController: UITableViewController {

    private(set) var project: CDProject?
    private(set) var meeting: CDMeeting?

    static func initWith(project: CDProject?, meeting: CDMeeting?) -> MeetingViewController {
    let storyboard = UIStoryboard(name: "Meeting", bundle: nil)
    let meetingVC = storyboard.instantiateViewController(withIdentifier: "MeetingVCId") as! MeetingViewController
    meetingVC.project = project
    meetingVC.meeting = meeting
    return meetingVC
    }
    }


    Child Class-1:



    class MeetingInfoViewController: MeetingViewController {

    static func initWith(meeting: CDMeeting) -> MeetingInfoViewController {
    let meetingVC = MeetingViewController.initWith(project: nil, meeting: meeting)
    object_setClass(meetingVC, MeetingInfoViewController.self)
    return meetingVC as! MeetingInfoViewController
    }
    }


    Child Class-2:



    class MeetingCreateViewController: MeetingViewController {

    static func initWith(project: CDProject) -> MeetingCreateViewController {
    let meetingVC = MeetingViewController.initWith(project: project, meeting: nil)
    object_setClass(meetingVC, MeetingCreateViewController.self)
    return meetingVC as! MeetingCreateViewController
    }
    }


    This is working very fine, not any issue; but I'm just curious if:

    1 there's any other way to handle this scenario?

    2 this approach has any side-effects?

    3 this can be improved somehow?



    Also feel free to point out other things than initialisation!










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to use inheritance in UIViewController where base class has XIB in storyboard. I'm troubling with initiating different children classes with that XIB.

      I cannot use XIB file separately instead of storyboard because it has static UITableViewCells.



      So here is how I'm managing it currently using object_setClass method in SWIFT:
      Parent Class:



      class MeetingViewController: UITableViewController {

      private(set) var project: CDProject?
      private(set) var meeting: CDMeeting?

      static func initWith(project: CDProject?, meeting: CDMeeting?) -> MeetingViewController {
      let storyboard = UIStoryboard(name: "Meeting", bundle: nil)
      let meetingVC = storyboard.instantiateViewController(withIdentifier: "MeetingVCId") as! MeetingViewController
      meetingVC.project = project
      meetingVC.meeting = meeting
      return meetingVC
      }
      }


      Child Class-1:



      class MeetingInfoViewController: MeetingViewController {

      static func initWith(meeting: CDMeeting) -> MeetingInfoViewController {
      let meetingVC = MeetingViewController.initWith(project: nil, meeting: meeting)
      object_setClass(meetingVC, MeetingInfoViewController.self)
      return meetingVC as! MeetingInfoViewController
      }
      }


      Child Class-2:



      class MeetingCreateViewController: MeetingViewController {

      static func initWith(project: CDProject) -> MeetingCreateViewController {
      let meetingVC = MeetingViewController.initWith(project: project, meeting: nil)
      object_setClass(meetingVC, MeetingCreateViewController.self)
      return meetingVC as! MeetingCreateViewController
      }
      }


      This is working very fine, not any issue; but I'm just curious if:

      1 there's any other way to handle this scenario?

      2 this approach has any side-effects?

      3 this can be improved somehow?



      Also feel free to point out other things than initialisation!










      share|improve this question













      I'm trying to use inheritance in UIViewController where base class has XIB in storyboard. I'm troubling with initiating different children classes with that XIB.

      I cannot use XIB file separately instead of storyboard because it has static UITableViewCells.



      So here is how I'm managing it currently using object_setClass method in SWIFT:
      Parent Class:



      class MeetingViewController: UITableViewController {

      private(set) var project: CDProject?
      private(set) var meeting: CDMeeting?

      static func initWith(project: CDProject?, meeting: CDMeeting?) -> MeetingViewController {
      let storyboard = UIStoryboard(name: "Meeting", bundle: nil)
      let meetingVC = storyboard.instantiateViewController(withIdentifier: "MeetingVCId") as! MeetingViewController
      meetingVC.project = project
      meetingVC.meeting = meeting
      return meetingVC
      }
      }


      Child Class-1:



      class MeetingInfoViewController: MeetingViewController {

      static func initWith(meeting: CDMeeting) -> MeetingInfoViewController {
      let meetingVC = MeetingViewController.initWith(project: nil, meeting: meeting)
      object_setClass(meetingVC, MeetingInfoViewController.self)
      return meetingVC as! MeetingInfoViewController
      }
      }


      Child Class-2:



      class MeetingCreateViewController: MeetingViewController {

      static func initWith(project: CDProject) -> MeetingCreateViewController {
      let meetingVC = MeetingViewController.initWith(project: project, meeting: nil)
      object_setClass(meetingVC, MeetingCreateViewController.self)
      return meetingVC as! MeetingCreateViewController
      }
      }


      This is working very fine, not any issue; but I'm just curious if:

      1 there's any other way to handle this scenario?

      2 this approach has any side-effects?

      3 this can be improved somehow?



      Also feel free to point out other things than initialisation!







      swift ios inheritance






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 16:29









      D4ttatraya

      274113




      274113



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208079%2finitiating-child-viewcontroller-from-uistoryboard-in-ios%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208079%2finitiating-child-viewcontroller-from-uistoryboard-in-ios%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre