6 Replies
      Latest reply on Feb 14, 2020 1:05 PM by wlionel
      wlionel Level 1 Level 1 (0 points)
        let date = Date()
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "dd/MM/yyyy"
        
        let fetchRequest: NSFetchRequest = GroupRecord.fetchRequest()
                        fetchRequest.predicate = NSPredicate(format: "groupName == %@ ", groupNameItem)
                          do {
                              let items = try managedObjectContext.fetch(fetchRequest)
        
                            for item in items {
                              if let dateItem = (item.value(forKey: "date"))
                                            {
                                                print(dateItem)
                                      }
                            }
                  }

         

        I have a date attribute with dates. Record was saved, but I cannot get that date displayed in a textView. All I am getting is the current system date.

        Any help will be appreciated.

        • Re: How to fetch date
          Claude31 Level 8 Level 8 (8,145 points)

          Where do you put in the textView ? You don't show in code.

           

          What result of print do you get ?

            • Re: How to fetch date
              wlionel Level 1 Level 1 (0 points)

              I don't know why but it says reply is currently being moderated I there any way you can see the reply?

                • Re: How to fetch date
                  Claude31 Level 8 Level 8 (8,145 points)

                  Did you post a url (in the request message for instance) ? If so, edit the header as h ttps with a space.

                    • Re: How to fetch date
                      wlionel Level 1 Level 1 (0 points)

                      let firstPart = (item.value(forKey: "date")!)

                        print ("First part is \(firstPart)")

                        let secondPart = ("Grade") + (" ") + (gradeItem)

                        let thirdPart = (groupNameItem)  + (" ") + (groupScoreItem)

                        let fourthPart = (formatingDate) + (" ") + ("Group Score So Far is") + ("  ") + (totalScore) + "\n"

                       

                      let newLine =  secondPart + "  " + thirdPart + " " + fourthPart + "  " + fifthPart // Display in TextView

                      studentsText?.string = studentsText!.string  +  newLine + "\n" + "\n" // TextView output

                        • Re: How to fetch date
                          Claude31 Level 8 Level 8 (8,145 points)

                          So, please tell what you get from print:

                           

                            let firstPart = (item.value(forKey: "date")!)
                          
                            print ("First part is \(firstPart)")          // WHAT DO YOU GET HERE ?
                          
                            let secondPart = ("Grade") + (" ") + (gradeItem)
                            let thirdPart = (groupNameItem)  + (" ") + (groupScoreItem)
                            let fourthPart = (formatingDate) + (" ") + ("Group Score So Far is") + ("  ") + (totalScore) + "\n"
                           
                          // THERE IS NO firstPart HERE. INTENTIONAL ?
                          let newLine =  secondPart + "  " + thirdPart + " " + fourthPart + "  " + fifthPart // Display in TextView
                          studentsText?.string = studentsText!.string  +  newLine + "\n" + "\n" // TextView output