Unlock Content based on Day (iOS App with Xcode)












0














I am trying to get create an app where you can unlock a certain picture every day throughout the month of December, like an advent calendar.



So if the user is pressing the button for a certain day (all days have a button with their date on) the app shall compare the current date on the device to the unlock date. For example:



If the user is pressing the button for the 01.12.18 (dd.MM.yy) and it currently ist that day or any day later it shall display picture number one.
Else: (if the day isn't reached yet) the user shall see another picture, that says sth. like "You're too early! Please wait some more."



Any suggestions or example codes are very appreciated!



The prototype of the code looks like this:



import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
}

@IBOutlet weak var dailyContent: UIImageView!

@IBAction func türchen1Button(_ sender: Any) {

// if 01.12.18 (dd.MM.yy) is today or past today
// dailyContent.image = picture1
//
// else if 01.12.18 (dd.MM.yy) is in the future
// dailyContent.image = pictureTooEarly
}
}


This app shall be a present for my girlfriend and I appreciate every help!
Thank you in advance!
Benjamin










share|improve this question



























    0














    I am trying to get create an app where you can unlock a certain picture every day throughout the month of December, like an advent calendar.



    So if the user is pressing the button for a certain day (all days have a button with their date on) the app shall compare the current date on the device to the unlock date. For example:



    If the user is pressing the button for the 01.12.18 (dd.MM.yy) and it currently ist that day or any day later it shall display picture number one.
    Else: (if the day isn't reached yet) the user shall see another picture, that says sth. like "You're too early! Please wait some more."



    Any suggestions or example codes are very appreciated!



    The prototype of the code looks like this:



    import UIKit

    class ViewController: UIViewController {

    override func viewDidLoad() {
    super.viewDidLoad()
    }

    @IBOutlet weak var dailyContent: UIImageView!

    @IBAction func türchen1Button(_ sender: Any) {

    // if 01.12.18 (dd.MM.yy) is today or past today
    // dailyContent.image = picture1
    //
    // else if 01.12.18 (dd.MM.yy) is in the future
    // dailyContent.image = pictureTooEarly
    }
    }


    This app shall be a present for my girlfriend and I appreciate every help!
    Thank you in advance!
    Benjamin










    share|improve this question

























      0












      0








      0







      I am trying to get create an app where you can unlock a certain picture every day throughout the month of December, like an advent calendar.



      So if the user is pressing the button for a certain day (all days have a button with their date on) the app shall compare the current date on the device to the unlock date. For example:



      If the user is pressing the button for the 01.12.18 (dd.MM.yy) and it currently ist that day or any day later it shall display picture number one.
      Else: (if the day isn't reached yet) the user shall see another picture, that says sth. like "You're too early! Please wait some more."



      Any suggestions or example codes are very appreciated!



      The prototype of the code looks like this:



      import UIKit

      class ViewController: UIViewController {

      override func viewDidLoad() {
      super.viewDidLoad()
      }

      @IBOutlet weak var dailyContent: UIImageView!

      @IBAction func türchen1Button(_ sender: Any) {

      // if 01.12.18 (dd.MM.yy) is today or past today
      // dailyContent.image = picture1
      //
      // else if 01.12.18 (dd.MM.yy) is in the future
      // dailyContent.image = pictureTooEarly
      }
      }


      This app shall be a present for my girlfriend and I appreciate every help!
      Thank you in advance!
      Benjamin










      share|improve this question













      I am trying to get create an app where you can unlock a certain picture every day throughout the month of December, like an advent calendar.



      So if the user is pressing the button for a certain day (all days have a button with their date on) the app shall compare the current date on the device to the unlock date. For example:



      If the user is pressing the button for the 01.12.18 (dd.MM.yy) and it currently ist that day or any day later it shall display picture number one.
      Else: (if the day isn't reached yet) the user shall see another picture, that says sth. like "You're too early! Please wait some more."



      Any suggestions or example codes are very appreciated!



      The prototype of the code looks like this:



      import UIKit

      class ViewController: UIViewController {

      override func viewDidLoad() {
      super.viewDidLoad()
      }

      @IBOutlet weak var dailyContent: UIImageView!

      @IBAction func türchen1Button(_ sender: Any) {

      // if 01.12.18 (dd.MM.yy) is today or past today
      // dailyContent.image = picture1
      //
      // else if 01.12.18 (dd.MM.yy) is in the future
      // dailyContent.image = pictureTooEarly
      }
      }


      This app shall be a present for my girlfriend and I appreciate every help!
      Thank you in advance!
      Benjamin







      ios swift4 xcode10






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 17:24









      Benjamin H.

      53




      53
























          1 Answer
          1






          active

          oldest

          votes


















          0















          • Assign the tags 1 - 24 to the buttons which represent the days.


          • Use one IBAction and connect all buttons to this action.



            @IBAction func türchenButton(_ sender: UIButton) { 



          • In the body of the action get the current year and create a date of the corresponding button and check if the date is in the future



                let now = Date()
            let calendar = Calendar.current
            let currentYear = calendar.component(.year, from: now)
            let türchenComponents = DateComponents(year: currentYear, month: 12, day: sender.tag)
            let türchenDay = calendar.date(from: türchenComponents)!
            if calendar.compare(türchenDay, to: now, toGranularity: .day) == .orderedDescending {
            // is in the future
            dailyContent.image = pictureTooEarly
            } else {
            // is today or past today
            dailyContent.image = picture1
            }
            }







          share|improve this answer





















          • We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
            – Satish
            Nov 19 '18 at 18:35










          • @Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
            – vadian
            Nov 19 '18 at 18:55












          • Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
            – Benjamin H.
            Nov 19 '18 at 19:53












          • It works in every year because the currentYear is retrieved separately.
            – vadian
            Nov 19 '18 at 19:56










          • The code is supposed to work. Check if the tags are assigned correctly. For example print sender.tag
            – vadian
            Nov 28 '18 at 21:47











          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%2f53379760%2funlock-content-based-on-day-ios-app-with-xcode%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















          • Assign the tags 1 - 24 to the buttons which represent the days.


          • Use one IBAction and connect all buttons to this action.



            @IBAction func türchenButton(_ sender: UIButton) { 



          • In the body of the action get the current year and create a date of the corresponding button and check if the date is in the future



                let now = Date()
            let calendar = Calendar.current
            let currentYear = calendar.component(.year, from: now)
            let türchenComponents = DateComponents(year: currentYear, month: 12, day: sender.tag)
            let türchenDay = calendar.date(from: türchenComponents)!
            if calendar.compare(türchenDay, to: now, toGranularity: .day) == .orderedDescending {
            // is in the future
            dailyContent.image = pictureTooEarly
            } else {
            // is today or past today
            dailyContent.image = picture1
            }
            }







          share|improve this answer





















          • We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
            – Satish
            Nov 19 '18 at 18:35










          • @Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
            – vadian
            Nov 19 '18 at 18:55












          • Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
            – Benjamin H.
            Nov 19 '18 at 19:53












          • It works in every year because the currentYear is retrieved separately.
            – vadian
            Nov 19 '18 at 19:56










          • The code is supposed to work. Check if the tags are assigned correctly. For example print sender.tag
            – vadian
            Nov 28 '18 at 21:47
















          0















          • Assign the tags 1 - 24 to the buttons which represent the days.


          • Use one IBAction and connect all buttons to this action.



            @IBAction func türchenButton(_ sender: UIButton) { 



          • In the body of the action get the current year and create a date of the corresponding button and check if the date is in the future



                let now = Date()
            let calendar = Calendar.current
            let currentYear = calendar.component(.year, from: now)
            let türchenComponents = DateComponents(year: currentYear, month: 12, day: sender.tag)
            let türchenDay = calendar.date(from: türchenComponents)!
            if calendar.compare(türchenDay, to: now, toGranularity: .day) == .orderedDescending {
            // is in the future
            dailyContent.image = pictureTooEarly
            } else {
            // is today or past today
            dailyContent.image = picture1
            }
            }







          share|improve this answer





















          • We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
            – Satish
            Nov 19 '18 at 18:35










          • @Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
            – vadian
            Nov 19 '18 at 18:55












          • Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
            – Benjamin H.
            Nov 19 '18 at 19:53












          • It works in every year because the currentYear is retrieved separately.
            – vadian
            Nov 19 '18 at 19:56










          • The code is supposed to work. Check if the tags are assigned correctly. For example print sender.tag
            – vadian
            Nov 28 '18 at 21:47














          0












          0








          0







          • Assign the tags 1 - 24 to the buttons which represent the days.


          • Use one IBAction and connect all buttons to this action.



            @IBAction func türchenButton(_ sender: UIButton) { 



          • In the body of the action get the current year and create a date of the corresponding button and check if the date is in the future



                let now = Date()
            let calendar = Calendar.current
            let currentYear = calendar.component(.year, from: now)
            let türchenComponents = DateComponents(year: currentYear, month: 12, day: sender.tag)
            let türchenDay = calendar.date(from: türchenComponents)!
            if calendar.compare(türchenDay, to: now, toGranularity: .day) == .orderedDescending {
            // is in the future
            dailyContent.image = pictureTooEarly
            } else {
            // is today or past today
            dailyContent.image = picture1
            }
            }







          share|improve this answer













          • Assign the tags 1 - 24 to the buttons which represent the days.


          • Use one IBAction and connect all buttons to this action.



            @IBAction func türchenButton(_ sender: UIButton) { 



          • In the body of the action get the current year and create a date of the corresponding button and check if the date is in the future



                let now = Date()
            let calendar = Calendar.current
            let currentYear = calendar.component(.year, from: now)
            let türchenComponents = DateComponents(year: currentYear, month: 12, day: sender.tag)
            let türchenDay = calendar.date(from: türchenComponents)!
            if calendar.compare(türchenDay, to: now, toGranularity: .day) == .orderedDescending {
            // is in the future
            dailyContent.image = pictureTooEarly
            } else {
            // is today or past today
            dailyContent.image = picture1
            }
            }








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 17:50









          vadian

          143k13154170




          143k13154170












          • We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
            – Satish
            Nov 19 '18 at 18:35










          • @Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
            – vadian
            Nov 19 '18 at 18:55












          • Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
            – Benjamin H.
            Nov 19 '18 at 19:53












          • It works in every year because the currentYear is retrieved separately.
            – vadian
            Nov 19 '18 at 19:56










          • The code is supposed to work. Check if the tags are assigned correctly. For example print sender.tag
            – vadian
            Nov 28 '18 at 21:47


















          • We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
            – Satish
            Nov 19 '18 at 18:35










          • @Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
            – vadian
            Nov 19 '18 at 18:55












          • Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
            – Benjamin H.
            Nov 19 '18 at 19:53












          • It works in every year because the currentYear is retrieved separately.
            – vadian
            Nov 19 '18 at 19:56










          • The code is supposed to work. Check if the tags are assigned correctly. For example print sender.tag
            – vadian
            Nov 28 '18 at 21:47
















          We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
          – Satish
          Nov 19 '18 at 18:35




          We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
          – Satish
          Nov 19 '18 at 18:35












          @Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
          – vadian
          Nov 19 '18 at 18:55






          @Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
          – vadian
          Nov 19 '18 at 18:55














          Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
          – Benjamin H.
          Nov 19 '18 at 19:53






          Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
          – Benjamin H.
          Nov 19 '18 at 19:53














          It works in every year because the currentYear is retrieved separately.
          – vadian
          Nov 19 '18 at 19:56




          It works in every year because the currentYear is retrieved separately.
          – vadian
          Nov 19 '18 at 19:56












          The code is supposed to work. Check if the tags are assigned correctly. For example print sender.tag
          – vadian
          Nov 28 '18 at 21:47




          The code is supposed to work. Check if the tags are assigned correctly. For example print sender.tag
          – vadian
          Nov 28 '18 at 21:47


















          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%2f53379760%2funlock-content-based-on-day-ios-app-with-xcode%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

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]