How to save label content





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















in my TodoList I have a label that when add something in the Todo, show the date the day.



How can I save it? cause when I open my app I have always the date and time of when I open it.



Here is the code of the label with the date:



class TableViewCell: UITableViewCell {

@IBOutlet weak var Data: UILabel!

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

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

Data.text = String(describing: DateFormatter())

UserDefaults.standard.string(forKey: "Data")

let dataFormatter = DateFormatter()
dataFormatter.dateFormat = "dd/MM/yyyy H:mm a"
Data.text = dataFormatter.string(from: .init())

}
}









share|improve this question































    0















    in my TodoList I have a label that when add something in the Todo, show the date the day.



    How can I save it? cause when I open my app I have always the date and time of when I open it.



    Here is the code of the label with the date:



    class TableViewCell: UITableViewCell {

    @IBOutlet weak var Data: UILabel!

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

    override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    Data.text = String(describing: DateFormatter())

    UserDefaults.standard.string(forKey: "Data")

    let dataFormatter = DateFormatter()
    dataFormatter.dateFormat = "dd/MM/yyyy H:mm a"
    Data.text = dataFormatter.string(from: .init())

    }
    }









    share|improve this question



























      0












      0








      0








      in my TodoList I have a label that when add something in the Todo, show the date the day.



      How can I save it? cause when I open my app I have always the date and time of when I open it.



      Here is the code of the label with the date:



      class TableViewCell: UITableViewCell {

      @IBOutlet weak var Data: UILabel!

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

      override func setSelected(_ selected: Bool, animated: Bool) {
      super.setSelected(selected, animated: animated)

      Data.text = String(describing: DateFormatter())

      UserDefaults.standard.string(forKey: "Data")

      let dataFormatter = DateFormatter()
      dataFormatter.dateFormat = "dd/MM/yyyy H:mm a"
      Data.text = dataFormatter.string(from: .init())

      }
      }









      share|improve this question
















      in my TodoList I have a label that when add something in the Todo, show the date the day.



      How can I save it? cause when I open my app I have always the date and time of when I open it.



      Here is the code of the label with the date:



      class TableViewCell: UITableViewCell {

      @IBOutlet weak var Data: UILabel!

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

      override func setSelected(_ selected: Bool, animated: Bool) {
      super.setSelected(selected, animated: animated)

      Data.text = String(describing: DateFormatter())

      UserDefaults.standard.string(forKey: "Data")

      let dataFormatter = DateFormatter()
      dataFormatter.dateFormat = "dd/MM/yyyy H:mm a"
      Data.text = dataFormatter.string(from: .init())

      }
      }






      swift database save label






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 14:28









      impression7vx

      52411038




      52411038










      asked Jan 3 at 14:16









      MatteoMatteo

      395




      395
























          3 Answers
          3






          active

          oldest

          votes


















          0














          You can use UserDefaults.



          UserDefaults.standard.set(value: Any?, forKey: String)


          So, whenever you want to save you could do



          UserDefaults.standard.set(value: YourValue, forKey: "Data")





          share|improve this answer































            0














            First create global lazy variable for your DateFormatter since you don't want to create new one every time you need to set text.



            lazy var dateFormatter: DateFormatter = {
            let formatter = DateFormatter()
            formatter.dateFormat = "dd/MM/yyyy H:mm a"
            return formatter
            }()


            then you can set text of label like this (rename outlet for UILabel to start with small capital letter)



            data.text = dateFormatter.string(from: yourDate)




            Now for manipulating with Date object with UserDefaults



            Saving:



            UserDefaults.standard.set(yourDate, forKey: "date")


            Getting:



            if let date = UserDefaults.standard.object(forKey: "date") as? Date {
            ... // here you can use `date` of type `Date`
            }




            One advice at the end. Since you're using UITableViewCell, I suppose that you have more then one Date object saved in UserDefaults. I would recommend you to start using some database like Core Data or Realm.






            share|improve this answer































              0














              Move code inside setSelected to awakeFromNib



              also i expect this UserDefaults.standard.string(forKey: "Data") to return a value , so someWhere you should have UserDefaults.standard.set(value:"----Any value", forKey: "Data")



               guard let res =  UserDefaults.standard.object(forKey: "Data")  as? Date else { return }
              let dataFormatter = DateFormatter()
              dataFormatter.dateFormat = "dd/MM/yyyy H:mm a"
              Data.text = dataFormatter.string(from:res)


              For sett



               UserDefaults.standard.set(Date(), forKey: "Data")




              @IBOutlet weak var Data: UILabel!

              override func awakeFromNib() {
              super.awakeFromNib()
              UserDefaults.standard.set(Date(), forKey: "Data") // this line need to be placed where you need to store the date
              guard let storedDate = UserDefaults.standard.object(forKey: "Data") as? Date else { return } // here you read the stored date
              let dataFormatter = DateFormatter()
              dataFormatter.dateFormat = "dd/MM/yy H:mm a"
              Data.text = dataFormatter.string(from:storedDate)

              }





              share|improve this answer


























              • Hey I tried as you said but the app crash...this is the code. override func awakeFromNib() { super.awakeFromNib() guard (UserDefaults.standard.object(forKey: "Data") as? Data) != nil else { return } UserDefaults.standard.set(Data, forKey: "Data") let dataFormatter = DateFormatter() dataFormatter.dateFormat = "dd/MM/yy H:mm a" Data.text = dataFormatter.string(from: .init()) }

                – Matteo
                Jan 17 at 16:43













              • @Matteo what crash share it

                – Sh_Khan
                Jan 17 at 16:44











              • Thats the error.............Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object <UILabel: 0x7f80cbe659a0; frame = (352 11; 42 47); text = 'Label'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000003b8320>> for key Data' *** First throw call stack:

                – Matteo
                Jan 17 at 16:46






              • 1





                you try to save the label itself , you need UserDefaults.standard.set(Date(), forKey: "Data") verify it's not UserDefaults.standard.set(Data, forKey: "Data")

                – Sh_Khan
                Jan 17 at 16:47








              • 1





                can you show how you store and read it ?

                – Sh_Khan
                Jan 17 at 16:52












              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%2f54024081%2fhow-to-save-label-content%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              You can use UserDefaults.



              UserDefaults.standard.set(value: Any?, forKey: String)


              So, whenever you want to save you could do



              UserDefaults.standard.set(value: YourValue, forKey: "Data")





              share|improve this answer




























                0














                You can use UserDefaults.



                UserDefaults.standard.set(value: Any?, forKey: String)


                So, whenever you want to save you could do



                UserDefaults.standard.set(value: YourValue, forKey: "Data")





                share|improve this answer


























                  0












                  0








                  0







                  You can use UserDefaults.



                  UserDefaults.standard.set(value: Any?, forKey: String)


                  So, whenever you want to save you could do



                  UserDefaults.standard.set(value: YourValue, forKey: "Data")





                  share|improve this answer













                  You can use UserDefaults.



                  UserDefaults.standard.set(value: Any?, forKey: String)


                  So, whenever you want to save you could do



                  UserDefaults.standard.set(value: YourValue, forKey: "Data")






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 3 at 14:20









                  impression7vximpression7vx

                  52411038




                  52411038

























                      0














                      First create global lazy variable for your DateFormatter since you don't want to create new one every time you need to set text.



                      lazy var dateFormatter: DateFormatter = {
                      let formatter = DateFormatter()
                      formatter.dateFormat = "dd/MM/yyyy H:mm a"
                      return formatter
                      }()


                      then you can set text of label like this (rename outlet for UILabel to start with small capital letter)



                      data.text = dateFormatter.string(from: yourDate)




                      Now for manipulating with Date object with UserDefaults



                      Saving:



                      UserDefaults.standard.set(yourDate, forKey: "date")


                      Getting:



                      if let date = UserDefaults.standard.object(forKey: "date") as? Date {
                      ... // here you can use `date` of type `Date`
                      }




                      One advice at the end. Since you're using UITableViewCell, I suppose that you have more then one Date object saved in UserDefaults. I would recommend you to start using some database like Core Data or Realm.






                      share|improve this answer




























                        0














                        First create global lazy variable for your DateFormatter since you don't want to create new one every time you need to set text.



                        lazy var dateFormatter: DateFormatter = {
                        let formatter = DateFormatter()
                        formatter.dateFormat = "dd/MM/yyyy H:mm a"
                        return formatter
                        }()


                        then you can set text of label like this (rename outlet for UILabel to start with small capital letter)



                        data.text = dateFormatter.string(from: yourDate)




                        Now for manipulating with Date object with UserDefaults



                        Saving:



                        UserDefaults.standard.set(yourDate, forKey: "date")


                        Getting:



                        if let date = UserDefaults.standard.object(forKey: "date") as? Date {
                        ... // here you can use `date` of type `Date`
                        }




                        One advice at the end. Since you're using UITableViewCell, I suppose that you have more then one Date object saved in UserDefaults. I would recommend you to start using some database like Core Data or Realm.






                        share|improve this answer


























                          0












                          0








                          0







                          First create global lazy variable for your DateFormatter since you don't want to create new one every time you need to set text.



                          lazy var dateFormatter: DateFormatter = {
                          let formatter = DateFormatter()
                          formatter.dateFormat = "dd/MM/yyyy H:mm a"
                          return formatter
                          }()


                          then you can set text of label like this (rename outlet for UILabel to start with small capital letter)



                          data.text = dateFormatter.string(from: yourDate)




                          Now for manipulating with Date object with UserDefaults



                          Saving:



                          UserDefaults.standard.set(yourDate, forKey: "date")


                          Getting:



                          if let date = UserDefaults.standard.object(forKey: "date") as? Date {
                          ... // here you can use `date` of type `Date`
                          }




                          One advice at the end. Since you're using UITableViewCell, I suppose that you have more then one Date object saved in UserDefaults. I would recommend you to start using some database like Core Data or Realm.






                          share|improve this answer













                          First create global lazy variable for your DateFormatter since you don't want to create new one every time you need to set text.



                          lazy var dateFormatter: DateFormatter = {
                          let formatter = DateFormatter()
                          formatter.dateFormat = "dd/MM/yyyy H:mm a"
                          return formatter
                          }()


                          then you can set text of label like this (rename outlet for UILabel to start with small capital letter)



                          data.text = dateFormatter.string(from: yourDate)




                          Now for manipulating with Date object with UserDefaults



                          Saving:



                          UserDefaults.standard.set(yourDate, forKey: "date")


                          Getting:



                          if let date = UserDefaults.standard.object(forKey: "date") as? Date {
                          ... // here you can use `date` of type `Date`
                          }




                          One advice at the end. Since you're using UITableViewCell, I suppose that you have more then one Date object saved in UserDefaults. I would recommend you to start using some database like Core Data or Realm.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 3 at 15:05









                          Robert DreslerRobert Dresler

                          8,1222727




                          8,1222727























                              0














                              Move code inside setSelected to awakeFromNib



                              also i expect this UserDefaults.standard.string(forKey: "Data") to return a value , so someWhere you should have UserDefaults.standard.set(value:"----Any value", forKey: "Data")



                               guard let res =  UserDefaults.standard.object(forKey: "Data")  as? Date else { return }
                              let dataFormatter = DateFormatter()
                              dataFormatter.dateFormat = "dd/MM/yyyy H:mm a"
                              Data.text = dataFormatter.string(from:res)


                              For sett



                               UserDefaults.standard.set(Date(), forKey: "Data")




                              @IBOutlet weak var Data: UILabel!

                              override func awakeFromNib() {
                              super.awakeFromNib()
                              UserDefaults.standard.set(Date(), forKey: "Data") // this line need to be placed where you need to store the date
                              guard let storedDate = UserDefaults.standard.object(forKey: "Data") as? Date else { return } // here you read the stored date
                              let dataFormatter = DateFormatter()
                              dataFormatter.dateFormat = "dd/MM/yy H:mm a"
                              Data.text = dataFormatter.string(from:storedDate)

                              }





                              share|improve this answer


























                              • Hey I tried as you said but the app crash...this is the code. override func awakeFromNib() { super.awakeFromNib() guard (UserDefaults.standard.object(forKey: "Data") as? Data) != nil else { return } UserDefaults.standard.set(Data, forKey: "Data") let dataFormatter = DateFormatter() dataFormatter.dateFormat = "dd/MM/yy H:mm a" Data.text = dataFormatter.string(from: .init()) }

                                – Matteo
                                Jan 17 at 16:43













                              • @Matteo what crash share it

                                – Sh_Khan
                                Jan 17 at 16:44











                              • Thats the error.............Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object <UILabel: 0x7f80cbe659a0; frame = (352 11; 42 47); text = 'Label'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000003b8320>> for key Data' *** First throw call stack:

                                – Matteo
                                Jan 17 at 16:46






                              • 1





                                you try to save the label itself , you need UserDefaults.standard.set(Date(), forKey: "Data") verify it's not UserDefaults.standard.set(Data, forKey: "Data")

                                – Sh_Khan
                                Jan 17 at 16:47








                              • 1





                                can you show how you store and read it ?

                                – Sh_Khan
                                Jan 17 at 16:52
















                              0














                              Move code inside setSelected to awakeFromNib



                              also i expect this UserDefaults.standard.string(forKey: "Data") to return a value , so someWhere you should have UserDefaults.standard.set(value:"----Any value", forKey: "Data")



                               guard let res =  UserDefaults.standard.object(forKey: "Data")  as? Date else { return }
                              let dataFormatter = DateFormatter()
                              dataFormatter.dateFormat = "dd/MM/yyyy H:mm a"
                              Data.text = dataFormatter.string(from:res)


                              For sett



                               UserDefaults.standard.set(Date(), forKey: "Data")




                              @IBOutlet weak var Data: UILabel!

                              override func awakeFromNib() {
                              super.awakeFromNib()
                              UserDefaults.standard.set(Date(), forKey: "Data") // this line need to be placed where you need to store the date
                              guard let storedDate = UserDefaults.standard.object(forKey: "Data") as? Date else { return } // here you read the stored date
                              let dataFormatter = DateFormatter()
                              dataFormatter.dateFormat = "dd/MM/yy H:mm a"
                              Data.text = dataFormatter.string(from:storedDate)

                              }





                              share|improve this answer


























                              • Hey I tried as you said but the app crash...this is the code. override func awakeFromNib() { super.awakeFromNib() guard (UserDefaults.standard.object(forKey: "Data") as? Data) != nil else { return } UserDefaults.standard.set(Data, forKey: "Data") let dataFormatter = DateFormatter() dataFormatter.dateFormat = "dd/MM/yy H:mm a" Data.text = dataFormatter.string(from: .init()) }

                                – Matteo
                                Jan 17 at 16:43













                              • @Matteo what crash share it

                                – Sh_Khan
                                Jan 17 at 16:44











                              • Thats the error.............Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object <UILabel: 0x7f80cbe659a0; frame = (352 11; 42 47); text = 'Label'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000003b8320>> for key Data' *** First throw call stack:

                                – Matteo
                                Jan 17 at 16:46






                              • 1





                                you try to save the label itself , you need UserDefaults.standard.set(Date(), forKey: "Data") verify it's not UserDefaults.standard.set(Data, forKey: "Data")

                                – Sh_Khan
                                Jan 17 at 16:47








                              • 1





                                can you show how you store and read it ?

                                – Sh_Khan
                                Jan 17 at 16:52














                              0












                              0








                              0







                              Move code inside setSelected to awakeFromNib



                              also i expect this UserDefaults.standard.string(forKey: "Data") to return a value , so someWhere you should have UserDefaults.standard.set(value:"----Any value", forKey: "Data")



                               guard let res =  UserDefaults.standard.object(forKey: "Data")  as? Date else { return }
                              let dataFormatter = DateFormatter()
                              dataFormatter.dateFormat = "dd/MM/yyyy H:mm a"
                              Data.text = dataFormatter.string(from:res)


                              For sett



                               UserDefaults.standard.set(Date(), forKey: "Data")




                              @IBOutlet weak var Data: UILabel!

                              override func awakeFromNib() {
                              super.awakeFromNib()
                              UserDefaults.standard.set(Date(), forKey: "Data") // this line need to be placed where you need to store the date
                              guard let storedDate = UserDefaults.standard.object(forKey: "Data") as? Date else { return } // here you read the stored date
                              let dataFormatter = DateFormatter()
                              dataFormatter.dateFormat = "dd/MM/yy H:mm a"
                              Data.text = dataFormatter.string(from:storedDate)

                              }





                              share|improve this answer















                              Move code inside setSelected to awakeFromNib



                              also i expect this UserDefaults.standard.string(forKey: "Data") to return a value , so someWhere you should have UserDefaults.standard.set(value:"----Any value", forKey: "Data")



                               guard let res =  UserDefaults.standard.object(forKey: "Data")  as? Date else { return }
                              let dataFormatter = DateFormatter()
                              dataFormatter.dateFormat = "dd/MM/yyyy H:mm a"
                              Data.text = dataFormatter.string(from:res)


                              For sett



                               UserDefaults.standard.set(Date(), forKey: "Data")




                              @IBOutlet weak var Data: UILabel!

                              override func awakeFromNib() {
                              super.awakeFromNib()
                              UserDefaults.standard.set(Date(), forKey: "Data") // this line need to be placed where you need to store the date
                              guard let storedDate = UserDefaults.standard.object(forKey: "Data") as? Date else { return } // here you read the stored date
                              let dataFormatter = DateFormatter()
                              dataFormatter.dateFormat = "dd/MM/yy H:mm a"
                              Data.text = dataFormatter.string(from:storedDate)

                              }






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jan 17 at 17:00

























                              answered Jan 3 at 14:19









                              Sh_KhanSh_Khan

                              47.7k51433




                              47.7k51433













                              • Hey I tried as you said but the app crash...this is the code. override func awakeFromNib() { super.awakeFromNib() guard (UserDefaults.standard.object(forKey: "Data") as? Data) != nil else { return } UserDefaults.standard.set(Data, forKey: "Data") let dataFormatter = DateFormatter() dataFormatter.dateFormat = "dd/MM/yy H:mm a" Data.text = dataFormatter.string(from: .init()) }

                                – Matteo
                                Jan 17 at 16:43













                              • @Matteo what crash share it

                                – Sh_Khan
                                Jan 17 at 16:44











                              • Thats the error.............Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object <UILabel: 0x7f80cbe659a0; frame = (352 11; 42 47); text = 'Label'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000003b8320>> for key Data' *** First throw call stack:

                                – Matteo
                                Jan 17 at 16:46






                              • 1





                                you try to save the label itself , you need UserDefaults.standard.set(Date(), forKey: "Data") verify it's not UserDefaults.standard.set(Data, forKey: "Data")

                                – Sh_Khan
                                Jan 17 at 16:47








                              • 1





                                can you show how you store and read it ?

                                – Sh_Khan
                                Jan 17 at 16:52



















                              • Hey I tried as you said but the app crash...this is the code. override func awakeFromNib() { super.awakeFromNib() guard (UserDefaults.standard.object(forKey: "Data") as? Data) != nil else { return } UserDefaults.standard.set(Data, forKey: "Data") let dataFormatter = DateFormatter() dataFormatter.dateFormat = "dd/MM/yy H:mm a" Data.text = dataFormatter.string(from: .init()) }

                                – Matteo
                                Jan 17 at 16:43













                              • @Matteo what crash share it

                                – Sh_Khan
                                Jan 17 at 16:44











                              • Thats the error.............Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object <UILabel: 0x7f80cbe659a0; frame = (352 11; 42 47); text = 'Label'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000003b8320>> for key Data' *** First throw call stack:

                                – Matteo
                                Jan 17 at 16:46






                              • 1





                                you try to save the label itself , you need UserDefaults.standard.set(Date(), forKey: "Data") verify it's not UserDefaults.standard.set(Data, forKey: "Data")

                                – Sh_Khan
                                Jan 17 at 16:47








                              • 1





                                can you show how you store and read it ?

                                – Sh_Khan
                                Jan 17 at 16:52

















                              Hey I tried as you said but the app crash...this is the code. override func awakeFromNib() { super.awakeFromNib() guard (UserDefaults.standard.object(forKey: "Data") as? Data) != nil else { return } UserDefaults.standard.set(Data, forKey: "Data") let dataFormatter = DateFormatter() dataFormatter.dateFormat = "dd/MM/yy H:mm a" Data.text = dataFormatter.string(from: .init()) }

                              – Matteo
                              Jan 17 at 16:43







                              Hey I tried as you said but the app crash...this is the code. override func awakeFromNib() { super.awakeFromNib() guard (UserDefaults.standard.object(forKey: "Data") as? Data) != nil else { return } UserDefaults.standard.set(Data, forKey: "Data") let dataFormatter = DateFormatter() dataFormatter.dateFormat = "dd/MM/yy H:mm a" Data.text = dataFormatter.string(from: .init()) }

                              – Matteo
                              Jan 17 at 16:43















                              @Matteo what crash share it

                              – Sh_Khan
                              Jan 17 at 16:44





                              @Matteo what crash share it

                              – Sh_Khan
                              Jan 17 at 16:44













                              Thats the error.............Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object <UILabel: 0x7f80cbe659a0; frame = (352 11; 42 47); text = 'Label'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000003b8320>> for key Data' *** First throw call stack:

                              – Matteo
                              Jan 17 at 16:46





                              Thats the error.............Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object <UILabel: 0x7f80cbe659a0; frame = (352 11; 42 47); text = 'Label'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000003b8320>> for key Data' *** First throw call stack:

                              – Matteo
                              Jan 17 at 16:46




                              1




                              1





                              you try to save the label itself , you need UserDefaults.standard.set(Date(), forKey: "Data") verify it's not UserDefaults.standard.set(Data, forKey: "Data")

                              – Sh_Khan
                              Jan 17 at 16:47







                              you try to save the label itself , you need UserDefaults.standard.set(Date(), forKey: "Data") verify it's not UserDefaults.standard.set(Data, forKey: "Data")

                              – Sh_Khan
                              Jan 17 at 16:47






                              1




                              1





                              can you show how you store and read it ?

                              – Sh_Khan
                              Jan 17 at 16:52





                              can you show how you store and read it ?

                              – Sh_Khan
                              Jan 17 at 16:52


















                              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.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024081%2fhow-to-save-label-content%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

                              MongoDB - Not Authorized To Execute Command

                              How to fix TextFormField cause rebuild widget in Flutter

                              in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith