Redux: best practice (using Swift)












1














I need advice on best practice with Redux in iOS app.



I am trying to master this architectural pattern, but I am not using Redux+Reactive approach. Just ReSwift + simple declarative code.



The problem I am facing is basic. Storing UIImage.
As far as I've seen in some tutorial, it is not advisable to store UIImage as a state's property. Hence, it is recommended to store the path to the image.



To obtain the path, we need to save the image locally to disk. The image comes from phone's media library. So, saving it locally takes time (it is done synchronously, because I don't want to add async tasks for the simplest screen with one UIImageView).



Fortunately, image picker controller provides us with the image url:



func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
let imageURL = info[.imageURL] as? URL
picker.dismiss(animated: true, completion: nil)
store.dispatch(DidPickImageAction(imageURL: imageURL))
}


I can use it, without rewriting image into the file, which solves the problem.



But, there is also option to make new image via camera. In that case info dictionary does not have .imageURL, which again leads me to the necessity to write image to file.



This makes me want to just store UIImage in state, but since it is against Redux rules, I am asking:



What is the best practice in working with images in Redux architecture?



Any help will be very much appreciated.










share|improve this question





























    1














    I need advice on best practice with Redux in iOS app.



    I am trying to master this architectural pattern, but I am not using Redux+Reactive approach. Just ReSwift + simple declarative code.



    The problem I am facing is basic. Storing UIImage.
    As far as I've seen in some tutorial, it is not advisable to store UIImage as a state's property. Hence, it is recommended to store the path to the image.



    To obtain the path, we need to save the image locally to disk. The image comes from phone's media library. So, saving it locally takes time (it is done synchronously, because I don't want to add async tasks for the simplest screen with one UIImageView).



    Fortunately, image picker controller provides us with the image url:



    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
    let imageURL = info[.imageURL] as? URL
    picker.dismiss(animated: true, completion: nil)
    store.dispatch(DidPickImageAction(imageURL: imageURL))
    }


    I can use it, without rewriting image into the file, which solves the problem.



    But, there is also option to make new image via camera. In that case info dictionary does not have .imageURL, which again leads me to the necessity to write image to file.



    This makes me want to just store UIImage in state, but since it is against Redux rules, I am asking:



    What is the best practice in working with images in Redux architecture?



    Any help will be very much appreciated.










    share|improve this question



























      1












      1








      1







      I need advice on best practice with Redux in iOS app.



      I am trying to master this architectural pattern, but I am not using Redux+Reactive approach. Just ReSwift + simple declarative code.



      The problem I am facing is basic. Storing UIImage.
      As far as I've seen in some tutorial, it is not advisable to store UIImage as a state's property. Hence, it is recommended to store the path to the image.



      To obtain the path, we need to save the image locally to disk. The image comes from phone's media library. So, saving it locally takes time (it is done synchronously, because I don't want to add async tasks for the simplest screen with one UIImageView).



      Fortunately, image picker controller provides us with the image url:



      func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
      let imageURL = info[.imageURL] as? URL
      picker.dismiss(animated: true, completion: nil)
      store.dispatch(DidPickImageAction(imageURL: imageURL))
      }


      I can use it, without rewriting image into the file, which solves the problem.



      But, there is also option to make new image via camera. In that case info dictionary does not have .imageURL, which again leads me to the necessity to write image to file.



      This makes me want to just store UIImage in state, but since it is against Redux rules, I am asking:



      What is the best practice in working with images in Redux architecture?



      Any help will be very much appreciated.










      share|improve this question















      I need advice on best practice with Redux in iOS app.



      I am trying to master this architectural pattern, but I am not using Redux+Reactive approach. Just ReSwift + simple declarative code.



      The problem I am facing is basic. Storing UIImage.
      As far as I've seen in some tutorial, it is not advisable to store UIImage as a state's property. Hence, it is recommended to store the path to the image.



      To obtain the path, we need to save the image locally to disk. The image comes from phone's media library. So, saving it locally takes time (it is done synchronously, because I don't want to add async tasks for the simplest screen with one UIImageView).



      Fortunately, image picker controller provides us with the image url:



      func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
      let imageURL = info[.imageURL] as? URL
      picker.dismiss(animated: true, completion: nil)
      store.dispatch(DidPickImageAction(imageURL: imageURL))
      }


      I can use it, without rewriting image into the file, which solves the problem.



      But, there is also option to make new image via camera. In that case info dictionary does not have .imageURL, which again leads me to the necessity to write image to file.



      This makes me want to just store UIImage in state, but since it is against Redux rules, I am asking:



      What is the best practice in working with images in Redux architecture?



      Any help will be very much appreciated.







      ios swift redux uiimage reswift






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      user28434

      3,1581125




      3,1581125










      asked yesterday









      Evgeniy

      477413




      477413
























          1 Answer
          1






          active

          oldest

          votes


















          0














          This is not good to directly hold the images.



          Best approach you can do.




          1. Write you image in documents directory.

          2. Save images name in Core
            data

          3. Fetch image name with core data and get you image with document
            directory.






          share|improve this answer





















          • 1. Write to documents directory. - this is what I am actually doing right now. But since the task is syncronous, the user has to wait until image is saved, before image picker controller is dismissed. It takes around half a second, but it is still noticeable.
            – Evgeniy
            yesterday










          • You can call image save functionality in dismiss completion block. self.dismiss(animated: true, completion: { //completion block. }) 2. You can also show a loader until your image is save.
            – gaurav bajaj
            yesterday










          • If I call it in dismiss block, the user will see the empty image view for those half a second. I don't want to make a loader for really-really simple app, where you just select the image and see it. Redux is aimed at simplifying things, so I wonder if I can use it without overcomplications like unnecessary loader.
            – Evgeniy
            yesterday











          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',
          autoActivateHeartbeat: false,
          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%2f53944626%2fredux-best-practice-using-swift%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









          0














          This is not good to directly hold the images.



          Best approach you can do.




          1. Write you image in documents directory.

          2. Save images name in Core
            data

          3. Fetch image name with core data and get you image with document
            directory.






          share|improve this answer





















          • 1. Write to documents directory. - this is what I am actually doing right now. But since the task is syncronous, the user has to wait until image is saved, before image picker controller is dismissed. It takes around half a second, but it is still noticeable.
            – Evgeniy
            yesterday










          • You can call image save functionality in dismiss completion block. self.dismiss(animated: true, completion: { //completion block. }) 2. You can also show a loader until your image is save.
            – gaurav bajaj
            yesterday










          • If I call it in dismiss block, the user will see the empty image view for those half a second. I don't want to make a loader for really-really simple app, where you just select the image and see it. Redux is aimed at simplifying things, so I wonder if I can use it without overcomplications like unnecessary loader.
            – Evgeniy
            yesterday
















          0














          This is not good to directly hold the images.



          Best approach you can do.




          1. Write you image in documents directory.

          2. Save images name in Core
            data

          3. Fetch image name with core data and get you image with document
            directory.






          share|improve this answer





















          • 1. Write to documents directory. - this is what I am actually doing right now. But since the task is syncronous, the user has to wait until image is saved, before image picker controller is dismissed. It takes around half a second, but it is still noticeable.
            – Evgeniy
            yesterday










          • You can call image save functionality in dismiss completion block. self.dismiss(animated: true, completion: { //completion block. }) 2. You can also show a loader until your image is save.
            – gaurav bajaj
            yesterday










          • If I call it in dismiss block, the user will see the empty image view for those half a second. I don't want to make a loader for really-really simple app, where you just select the image and see it. Redux is aimed at simplifying things, so I wonder if I can use it without overcomplications like unnecessary loader.
            – Evgeniy
            yesterday














          0












          0








          0






          This is not good to directly hold the images.



          Best approach you can do.




          1. Write you image in documents directory.

          2. Save images name in Core
            data

          3. Fetch image name with core data and get you image with document
            directory.






          share|improve this answer












          This is not good to directly hold the images.



          Best approach you can do.




          1. Write you image in documents directory.

          2. Save images name in Core
            data

          3. Fetch image name with core data and get you image with document
            directory.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          gaurav bajaj

          116




          116












          • 1. Write to documents directory. - this is what I am actually doing right now. But since the task is syncronous, the user has to wait until image is saved, before image picker controller is dismissed. It takes around half a second, but it is still noticeable.
            – Evgeniy
            yesterday










          • You can call image save functionality in dismiss completion block. self.dismiss(animated: true, completion: { //completion block. }) 2. You can also show a loader until your image is save.
            – gaurav bajaj
            yesterday










          • If I call it in dismiss block, the user will see the empty image view for those half a second. I don't want to make a loader for really-really simple app, where you just select the image and see it. Redux is aimed at simplifying things, so I wonder if I can use it without overcomplications like unnecessary loader.
            – Evgeniy
            yesterday


















          • 1. Write to documents directory. - this is what I am actually doing right now. But since the task is syncronous, the user has to wait until image is saved, before image picker controller is dismissed. It takes around half a second, but it is still noticeable.
            – Evgeniy
            yesterday










          • You can call image save functionality in dismiss completion block. self.dismiss(animated: true, completion: { //completion block. }) 2. You can also show a loader until your image is save.
            – gaurav bajaj
            yesterday










          • If I call it in dismiss block, the user will see the empty image view for those half a second. I don't want to make a loader for really-really simple app, where you just select the image and see it. Redux is aimed at simplifying things, so I wonder if I can use it without overcomplications like unnecessary loader.
            – Evgeniy
            yesterday
















          1. Write to documents directory. - this is what I am actually doing right now. But since the task is syncronous, the user has to wait until image is saved, before image picker controller is dismissed. It takes around half a second, but it is still noticeable.
          – Evgeniy
          yesterday




          1. Write to documents directory. - this is what I am actually doing right now. But since the task is syncronous, the user has to wait until image is saved, before image picker controller is dismissed. It takes around half a second, but it is still noticeable.
          – Evgeniy
          yesterday












          You can call image save functionality in dismiss completion block. self.dismiss(animated: true, completion: { //completion block. }) 2. You can also show a loader until your image is save.
          – gaurav bajaj
          yesterday




          You can call image save functionality in dismiss completion block. self.dismiss(animated: true, completion: { //completion block. }) 2. You can also show a loader until your image is save.
          – gaurav bajaj
          yesterday












          If I call it in dismiss block, the user will see the empty image view for those half a second. I don't want to make a loader for really-really simple app, where you just select the image and see it. Redux is aimed at simplifying things, so I wonder if I can use it without overcomplications like unnecessary loader.
          – Evgeniy
          yesterday




          If I call it in dismiss block, the user will see the empty image view for those half a second. I don't want to make a loader for really-really simple app, where you just select the image and see it. Redux is aimed at simplifying things, so I wonder if I can use it without overcomplications like unnecessary loader.
          – Evgeniy
          yesterday


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53944626%2fredux-best-practice-using-swift%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

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas