Swift: Changing view/screen depending on device orientation. What is “efficiency wise” the better option?









up vote
3
down vote

favorite
1












Introduction



I'm creating a calendar app in which one of the screens has a landscape view and a portrait view. For simplicity picture the iOS apple calendar in which the landscape view is a week view (i.e. completely different than the portrait view).



Issue



I'm getting a sense of bad code structure and potential loss of efficiency in my current code. Since I basically use the users battery and CPU for the week view concurrently with the portrait view even though not everyone uses the week view. What is the better practice in implementing a different presentation depending on device rotation?



Question




  • Which pattern would be the more efficient approach? Is there a third option I haven't considered that would result in better performance?

My attempts



(I've also included a code example (below) that shows my implementation of these attempts in code.)



  1. Two UIViewControllers that is segued and "popped" depending on conditions of device orientation in viewWillTransition(). Although that became quickly out of hand since the method triggers in all view controller currently in memory/navigationStack, resulting in additional copies of viewControllers in the navigation stack if you swap between right landscape and left landscape.


  2. Using one UIViewController and two UIView subclass that is initialized and communicating to the view controller through the delegate-protocol pattern. In which during the viewWillTransition() I simply animate an alpha change between the two UIViews depending on the device orientation.


Code example



(I have provided two simplification to illustrate my attempts described above, methods such as dataSource and delegate methods for UICollectionViews are not included are not included in the example below.)



Attempt 1:



class PortraitCalendar: UIViewController 
let portraitCalendarView : MonthCalendar =
// Setup of my portrait calendar, it is a UICollectionView subclass.


override func viewDidLoad()
super.viewDidLoad()
view.addSubview(portraitCalendarView)
// Additional setup..


override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
super.viewWillTransition(to: size, with: coordinator)
if UIDevice.current.orientation.isLandscape
performSegue(withIdentifier: "toLandscapeCalendar", sender: nil)




class LandscapeCalendar: UIViewController
let landscapeView : LandscapeView =
// Setup of the landscape view, a UICollectionView subclass.

override func viewDidLoad()
super.viewDidLoad()
view.addSubview(landscapeView)
// Additional setup..


override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
super.viewWillTransition(to: size, with: coordinator)
if UIDevice.current.orientation.isPortrait
navigationController?.popViewController(animated: true)





Attempt 2:



class PortraitCalendar: UIViewController, LandscapeCalendarDelegate 
let portraitCalendarView : MonthCalendar =
// Setup of my portrait calendar, it is a UICollectionView subclass.


// UIView subclass with a UICollectionView within it as a week calendar.
let landscapeCalendar = LandscapeView()

override func viewDidLoad()
super.viewDidLoad()
view.addSubview(portraitCalendarView)
view.addSubview(landscapeCalendar)
landscapeCalendar.alpha = 0
portraitCalendarView.alpha = 1
// Constraints and additional setup as well of course.


override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
super.viewWillTransition(to: size, with: coordinator)
if UIDevice.current.orientation.isLandscape
navigationController?.isToolbarHidden = true
self.view.layoutIfNeeded()

landscapeCalendarDelegate?.splitCalendarViewWillAppear()
UIView.animate(withDuration: 0.1)
self.portraitCalendarView.alpha = 0
self.landscapeCalendar.alpha = 1

else
self.portraitCalendarView.alpha = 1
self.landscapeCalendar.alpha = 0





Thanks for reading my question.










share|improve this question



























    up vote
    3
    down vote

    favorite
    1












    Introduction



    I'm creating a calendar app in which one of the screens has a landscape view and a portrait view. For simplicity picture the iOS apple calendar in which the landscape view is a week view (i.e. completely different than the portrait view).



    Issue



    I'm getting a sense of bad code structure and potential loss of efficiency in my current code. Since I basically use the users battery and CPU for the week view concurrently with the portrait view even though not everyone uses the week view. What is the better practice in implementing a different presentation depending on device rotation?



    Question




    • Which pattern would be the more efficient approach? Is there a third option I haven't considered that would result in better performance?

    My attempts



    (I've also included a code example (below) that shows my implementation of these attempts in code.)



    1. Two UIViewControllers that is segued and "popped" depending on conditions of device orientation in viewWillTransition(). Although that became quickly out of hand since the method triggers in all view controller currently in memory/navigationStack, resulting in additional copies of viewControllers in the navigation stack if you swap between right landscape and left landscape.


    2. Using one UIViewController and two UIView subclass that is initialized and communicating to the view controller through the delegate-protocol pattern. In which during the viewWillTransition() I simply animate an alpha change between the two UIViews depending on the device orientation.


    Code example



    (I have provided two simplification to illustrate my attempts described above, methods such as dataSource and delegate methods for UICollectionViews are not included are not included in the example below.)



    Attempt 1:



    class PortraitCalendar: UIViewController 
    let portraitCalendarView : MonthCalendar =
    // Setup of my portrait calendar, it is a UICollectionView subclass.


    override func viewDidLoad()
    super.viewDidLoad()
    view.addSubview(portraitCalendarView)
    // Additional setup..


    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
    super.viewWillTransition(to: size, with: coordinator)
    if UIDevice.current.orientation.isLandscape
    performSegue(withIdentifier: "toLandscapeCalendar", sender: nil)




    class LandscapeCalendar: UIViewController
    let landscapeView : LandscapeView =
    // Setup of the landscape view, a UICollectionView subclass.

    override func viewDidLoad()
    super.viewDidLoad()
    view.addSubview(landscapeView)
    // Additional setup..


    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
    super.viewWillTransition(to: size, with: coordinator)
    if UIDevice.current.orientation.isPortrait
    navigationController?.popViewController(animated: true)





    Attempt 2:



    class PortraitCalendar: UIViewController, LandscapeCalendarDelegate 
    let portraitCalendarView : MonthCalendar =
    // Setup of my portrait calendar, it is a UICollectionView subclass.


    // UIView subclass with a UICollectionView within it as a week calendar.
    let landscapeCalendar = LandscapeView()

    override func viewDidLoad()
    super.viewDidLoad()
    view.addSubview(portraitCalendarView)
    view.addSubview(landscapeCalendar)
    landscapeCalendar.alpha = 0
    portraitCalendarView.alpha = 1
    // Constraints and additional setup as well of course.


    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
    super.viewWillTransition(to: size, with: coordinator)
    if UIDevice.current.orientation.isLandscape
    navigationController?.isToolbarHidden = true
    self.view.layoutIfNeeded()

    landscapeCalendarDelegate?.splitCalendarViewWillAppear()
    UIView.animate(withDuration: 0.1)
    self.portraitCalendarView.alpha = 0
    self.landscapeCalendar.alpha = 1

    else
    self.portraitCalendarView.alpha = 1
    self.landscapeCalendar.alpha = 0





    Thanks for reading my question.










    share|improve this question

























      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      Introduction



      I'm creating a calendar app in which one of the screens has a landscape view and a portrait view. For simplicity picture the iOS apple calendar in which the landscape view is a week view (i.e. completely different than the portrait view).



      Issue



      I'm getting a sense of bad code structure and potential loss of efficiency in my current code. Since I basically use the users battery and CPU for the week view concurrently with the portrait view even though not everyone uses the week view. What is the better practice in implementing a different presentation depending on device rotation?



      Question




      • Which pattern would be the more efficient approach? Is there a third option I haven't considered that would result in better performance?

      My attempts



      (I've also included a code example (below) that shows my implementation of these attempts in code.)



      1. Two UIViewControllers that is segued and "popped" depending on conditions of device orientation in viewWillTransition(). Although that became quickly out of hand since the method triggers in all view controller currently in memory/navigationStack, resulting in additional copies of viewControllers in the navigation stack if you swap between right landscape and left landscape.


      2. Using one UIViewController and two UIView subclass that is initialized and communicating to the view controller through the delegate-protocol pattern. In which during the viewWillTransition() I simply animate an alpha change between the two UIViews depending on the device orientation.


      Code example



      (I have provided two simplification to illustrate my attempts described above, methods such as dataSource and delegate methods for UICollectionViews are not included are not included in the example below.)



      Attempt 1:



      class PortraitCalendar: UIViewController 
      let portraitCalendarView : MonthCalendar =
      // Setup of my portrait calendar, it is a UICollectionView subclass.


      override func viewDidLoad()
      super.viewDidLoad()
      view.addSubview(portraitCalendarView)
      // Additional setup..


      override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
      super.viewWillTransition(to: size, with: coordinator)
      if UIDevice.current.orientation.isLandscape
      performSegue(withIdentifier: "toLandscapeCalendar", sender: nil)




      class LandscapeCalendar: UIViewController
      let landscapeView : LandscapeView =
      // Setup of the landscape view, a UICollectionView subclass.

      override func viewDidLoad()
      super.viewDidLoad()
      view.addSubview(landscapeView)
      // Additional setup..


      override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
      super.viewWillTransition(to: size, with: coordinator)
      if UIDevice.current.orientation.isPortrait
      navigationController?.popViewController(animated: true)





      Attempt 2:



      class PortraitCalendar: UIViewController, LandscapeCalendarDelegate 
      let portraitCalendarView : MonthCalendar =
      // Setup of my portrait calendar, it is a UICollectionView subclass.


      // UIView subclass with a UICollectionView within it as a week calendar.
      let landscapeCalendar = LandscapeView()

      override func viewDidLoad()
      super.viewDidLoad()
      view.addSubview(portraitCalendarView)
      view.addSubview(landscapeCalendar)
      landscapeCalendar.alpha = 0
      portraitCalendarView.alpha = 1
      // Constraints and additional setup as well of course.


      override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
      super.viewWillTransition(to: size, with: coordinator)
      if UIDevice.current.orientation.isLandscape
      navigationController?.isToolbarHidden = true
      self.view.layoutIfNeeded()

      landscapeCalendarDelegate?.splitCalendarViewWillAppear()
      UIView.animate(withDuration: 0.1)
      self.portraitCalendarView.alpha = 0
      self.landscapeCalendar.alpha = 1

      else
      self.portraitCalendarView.alpha = 1
      self.landscapeCalendar.alpha = 0





      Thanks for reading my question.










      share|improve this question















      Introduction



      I'm creating a calendar app in which one of the screens has a landscape view and a portrait view. For simplicity picture the iOS apple calendar in which the landscape view is a week view (i.e. completely different than the portrait view).



      Issue



      I'm getting a sense of bad code structure and potential loss of efficiency in my current code. Since I basically use the users battery and CPU for the week view concurrently with the portrait view even though not everyone uses the week view. What is the better practice in implementing a different presentation depending on device rotation?



      Question




      • Which pattern would be the more efficient approach? Is there a third option I haven't considered that would result in better performance?

      My attempts



      (I've also included a code example (below) that shows my implementation of these attempts in code.)



      1. Two UIViewControllers that is segued and "popped" depending on conditions of device orientation in viewWillTransition(). Although that became quickly out of hand since the method triggers in all view controller currently in memory/navigationStack, resulting in additional copies of viewControllers in the navigation stack if you swap between right landscape and left landscape.


      2. Using one UIViewController and two UIView subclass that is initialized and communicating to the view controller through the delegate-protocol pattern. In which during the viewWillTransition() I simply animate an alpha change between the two UIViews depending on the device orientation.


      Code example



      (I have provided two simplification to illustrate my attempts described above, methods such as dataSource and delegate methods for UICollectionViews are not included are not included in the example below.)



      Attempt 1:



      class PortraitCalendar: UIViewController 
      let portraitCalendarView : MonthCalendar =
      // Setup of my portrait calendar, it is a UICollectionView subclass.


      override func viewDidLoad()
      super.viewDidLoad()
      view.addSubview(portraitCalendarView)
      // Additional setup..


      override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
      super.viewWillTransition(to: size, with: coordinator)
      if UIDevice.current.orientation.isLandscape
      performSegue(withIdentifier: "toLandscapeCalendar", sender: nil)




      class LandscapeCalendar: UIViewController
      let landscapeView : LandscapeView =
      // Setup of the landscape view, a UICollectionView subclass.

      override func viewDidLoad()
      super.viewDidLoad()
      view.addSubview(landscapeView)
      // Additional setup..


      override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
      super.viewWillTransition(to: size, with: coordinator)
      if UIDevice.current.orientation.isPortrait
      navigationController?.popViewController(animated: true)





      Attempt 2:



      class PortraitCalendar: UIViewController, LandscapeCalendarDelegate 
      let portraitCalendarView : MonthCalendar =
      // Setup of my portrait calendar, it is a UICollectionView subclass.


      // UIView subclass with a UICollectionView within it as a week calendar.
      let landscapeCalendar = LandscapeView()

      override func viewDidLoad()
      super.viewDidLoad()
      view.addSubview(portraitCalendarView)
      view.addSubview(landscapeCalendar)
      landscapeCalendar.alpha = 0
      portraitCalendarView.alpha = 1
      // Constraints and additional setup as well of course.


      override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
      super.viewWillTransition(to: size, with: coordinator)
      if UIDevice.current.orientation.isLandscape
      navigationController?.isToolbarHidden = true
      self.view.layoutIfNeeded()

      landscapeCalendarDelegate?.splitCalendarViewWillAppear()
      UIView.animate(withDuration: 0.1)
      self.portraitCalendarView.alpha = 0
      self.landscapeCalendar.alpha = 1

      else
      self.portraitCalendarView.alpha = 1
      self.landscapeCalendar.alpha = 0





      Thanks for reading my question.







      ios swift orientation landscape-portrait device-orientation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 15:49

























      asked Nov 9 at 15:08









      theoadahl

      14119




      14119






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          I'd definitely go for an option number 2.



          That way you encapsulate all the logic related to the calendar, for example for adding event or displaying it, in one view controller, without the need to reimplement the sane logic somewhere else (eg other view controller with landscape mode). Having two views for a different layout modes is not THAT easy to maintain, but if that's the only way to show the difference between the modes it really is a fine solution. And it's much easier to maintain than two view controllers with the very similar logic.






          share|improve this answer




















          • Thanks for posting an answer! Yes I agree, the first attempt quickly gave some strange behaviors. The problem I see with the 2nd attempt though, is that I basically need a protocol for each as well as having them both loaded in memory and running concurrently. I haven't tested them through CPU/memory usage, but I feel that since not everyone will use the week view of the calendar, I basically use their battery and CPU for it anyway. Is there a third option that would be more "intelligent" CPU wise?
            – theoadahl
            Nov 10 at 15:47










          • @theoadahl trust me having two views, even complex ones in memory is nothing big of a resource if they're coded properly. Also you don't always need delegation pattern to handle the work of your views. You could easily use closures or protocols (in a contract meaning of it). Performance wise I really doubt that having just two views in memory gonna cause some issues. If you're not interacting with those views, they also have no impact on CPU and battery life. So if you have one active view, only its interactions are counted.
            – inokey
            Nov 10 at 15:54











          • Ok i've played around with the second attempt and just like you said it doesn't seem to impact performance that much. Thank you for the insight. Cheers.
            – theoadahl
            Nov 13 at 20:13










          Your Answer






          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: "1"
          ;
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fstackoverflow.com%2fquestions%2f53228300%2fswift-changing-view-screen-depending-on-device-orientation-what-is-efficiency%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          I'd definitely go for an option number 2.



          That way you encapsulate all the logic related to the calendar, for example for adding event or displaying it, in one view controller, without the need to reimplement the sane logic somewhere else (eg other view controller with landscape mode). Having two views for a different layout modes is not THAT easy to maintain, but if that's the only way to show the difference between the modes it really is a fine solution. And it's much easier to maintain than two view controllers with the very similar logic.






          share|improve this answer




















          • Thanks for posting an answer! Yes I agree, the first attempt quickly gave some strange behaviors. The problem I see with the 2nd attempt though, is that I basically need a protocol for each as well as having them both loaded in memory and running concurrently. I haven't tested them through CPU/memory usage, but I feel that since not everyone will use the week view of the calendar, I basically use their battery and CPU for it anyway. Is there a third option that would be more "intelligent" CPU wise?
            – theoadahl
            Nov 10 at 15:47










          • @theoadahl trust me having two views, even complex ones in memory is nothing big of a resource if they're coded properly. Also you don't always need delegation pattern to handle the work of your views. You could easily use closures or protocols (in a contract meaning of it). Performance wise I really doubt that having just two views in memory gonna cause some issues. If you're not interacting with those views, they also have no impact on CPU and battery life. So if you have one active view, only its interactions are counted.
            – inokey
            Nov 10 at 15:54











          • Ok i've played around with the second attempt and just like you said it doesn't seem to impact performance that much. Thank you for the insight. Cheers.
            – theoadahl
            Nov 13 at 20:13














          up vote
          0
          down vote



          accepted










          I'd definitely go for an option number 2.



          That way you encapsulate all the logic related to the calendar, for example for adding event or displaying it, in one view controller, without the need to reimplement the sane logic somewhere else (eg other view controller with landscape mode). Having two views for a different layout modes is not THAT easy to maintain, but if that's the only way to show the difference between the modes it really is a fine solution. And it's much easier to maintain than two view controllers with the very similar logic.






          share|improve this answer




















          • Thanks for posting an answer! Yes I agree, the first attempt quickly gave some strange behaviors. The problem I see with the 2nd attempt though, is that I basically need a protocol for each as well as having them both loaded in memory and running concurrently. I haven't tested them through CPU/memory usage, but I feel that since not everyone will use the week view of the calendar, I basically use their battery and CPU for it anyway. Is there a third option that would be more "intelligent" CPU wise?
            – theoadahl
            Nov 10 at 15:47










          • @theoadahl trust me having two views, even complex ones in memory is nothing big of a resource if they're coded properly. Also you don't always need delegation pattern to handle the work of your views. You could easily use closures or protocols (in a contract meaning of it). Performance wise I really doubt that having just two views in memory gonna cause some issues. If you're not interacting with those views, they also have no impact on CPU and battery life. So if you have one active view, only its interactions are counted.
            – inokey
            Nov 10 at 15:54











          • Ok i've played around with the second attempt and just like you said it doesn't seem to impact performance that much. Thank you for the insight. Cheers.
            – theoadahl
            Nov 13 at 20:13












          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          I'd definitely go for an option number 2.



          That way you encapsulate all the logic related to the calendar, for example for adding event or displaying it, in one view controller, without the need to reimplement the sane logic somewhere else (eg other view controller with landscape mode). Having two views for a different layout modes is not THAT easy to maintain, but if that's the only way to show the difference between the modes it really is a fine solution. And it's much easier to maintain than two view controllers with the very similar logic.






          share|improve this answer












          I'd definitely go for an option number 2.



          That way you encapsulate all the logic related to the calendar, for example for adding event or displaying it, in one view controller, without the need to reimplement the sane logic somewhere else (eg other view controller with landscape mode). Having two views for a different layout modes is not THAT easy to maintain, but if that's the only way to show the difference between the modes it really is a fine solution. And it's much easier to maintain than two view controllers with the very similar logic.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 15:35









          inokey

          848617




          848617











          • Thanks for posting an answer! Yes I agree, the first attempt quickly gave some strange behaviors. The problem I see with the 2nd attempt though, is that I basically need a protocol for each as well as having them both loaded in memory and running concurrently. I haven't tested them through CPU/memory usage, but I feel that since not everyone will use the week view of the calendar, I basically use their battery and CPU for it anyway. Is there a third option that would be more "intelligent" CPU wise?
            – theoadahl
            Nov 10 at 15:47










          • @theoadahl trust me having two views, even complex ones in memory is nothing big of a resource if they're coded properly. Also you don't always need delegation pattern to handle the work of your views. You could easily use closures or protocols (in a contract meaning of it). Performance wise I really doubt that having just two views in memory gonna cause some issues. If you're not interacting with those views, they also have no impact on CPU and battery life. So if you have one active view, only its interactions are counted.
            – inokey
            Nov 10 at 15:54











          • Ok i've played around with the second attempt and just like you said it doesn't seem to impact performance that much. Thank you for the insight. Cheers.
            – theoadahl
            Nov 13 at 20:13
















          • Thanks for posting an answer! Yes I agree, the first attempt quickly gave some strange behaviors. The problem I see with the 2nd attempt though, is that I basically need a protocol for each as well as having them both loaded in memory and running concurrently. I haven't tested them through CPU/memory usage, but I feel that since not everyone will use the week view of the calendar, I basically use their battery and CPU for it anyway. Is there a third option that would be more "intelligent" CPU wise?
            – theoadahl
            Nov 10 at 15:47










          • @theoadahl trust me having two views, even complex ones in memory is nothing big of a resource if they're coded properly. Also you don't always need delegation pattern to handle the work of your views. You could easily use closures or protocols (in a contract meaning of it). Performance wise I really doubt that having just two views in memory gonna cause some issues. If you're not interacting with those views, they also have no impact on CPU and battery life. So if you have one active view, only its interactions are counted.
            – inokey
            Nov 10 at 15:54











          • Ok i've played around with the second attempt and just like you said it doesn't seem to impact performance that much. Thank you for the insight. Cheers.
            – theoadahl
            Nov 13 at 20:13















          Thanks for posting an answer! Yes I agree, the first attempt quickly gave some strange behaviors. The problem I see with the 2nd attempt though, is that I basically need a protocol for each as well as having them both loaded in memory and running concurrently. I haven't tested them through CPU/memory usage, but I feel that since not everyone will use the week view of the calendar, I basically use their battery and CPU for it anyway. Is there a third option that would be more "intelligent" CPU wise?
          – theoadahl
          Nov 10 at 15:47




          Thanks for posting an answer! Yes I agree, the first attempt quickly gave some strange behaviors. The problem I see with the 2nd attempt though, is that I basically need a protocol for each as well as having them both loaded in memory and running concurrently. I haven't tested them through CPU/memory usage, but I feel that since not everyone will use the week view of the calendar, I basically use their battery and CPU for it anyway. Is there a third option that would be more "intelligent" CPU wise?
          – theoadahl
          Nov 10 at 15:47












          @theoadahl trust me having two views, even complex ones in memory is nothing big of a resource if they're coded properly. Also you don't always need delegation pattern to handle the work of your views. You could easily use closures or protocols (in a contract meaning of it). Performance wise I really doubt that having just two views in memory gonna cause some issues. If you're not interacting with those views, they also have no impact on CPU and battery life. So if you have one active view, only its interactions are counted.
          – inokey
          Nov 10 at 15:54





          @theoadahl trust me having two views, even complex ones in memory is nothing big of a resource if they're coded properly. Also you don't always need delegation pattern to handle the work of your views. You could easily use closures or protocols (in a contract meaning of it). Performance wise I really doubt that having just two views in memory gonna cause some issues. If you're not interacting with those views, they also have no impact on CPU and battery life. So if you have one active view, only its interactions are counted.
          – inokey
          Nov 10 at 15:54













          Ok i've played around with the second attempt and just like you said it doesn't seem to impact performance that much. Thank you for the insight. Cheers.
          – theoadahl
          Nov 13 at 20:13




          Ok i've played around with the second attempt and just like you said it doesn't seem to impact performance that much. Thank you for the insight. Cheers.
          – theoadahl
          Nov 13 at 20:13

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228300%2fswift-changing-view-screen-depending-on-device-orientation-what-is-efficiency%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

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党