Post

Replies

Boosts

Views

Activity

Reply to Best practice for storing repeating dates in CoreData
that is pretty straightforward (here is the logic, not the code itself) get startDate get endDate declare repeatArray : [NSDate] = [] set runningDate = startDate while runningDate = endDate { append runningDate to the repeatArray add increment to runningDate repeats 1 : add 1 repeats 2 : add 7 repeats 3 : you need to increment the month } That should be straightforward to code
Topic: App & System Services SubTopic: General Tags:
Feb ’21
Reply to Best practice for storing repeating dates in CoreData
Well, I'll make extra effort to help, but it would be much better for you to try, fail, retry and get it.You would learn much more. I did not test the code below, so there may be some points to correct. In addition, is not specifically written for SwiftUI syntax. // get startDate let repeats = 2 let startDate = Date() // Change with what you get from the picker // get endDate let endDate = Date() // Change with the second date you get from picker var repeatArray : [Date] = [] var runningDate = startDate let calendar = Calendar.current let dateComponents = calendar.dateComponents( [.calendar, .timeZone, .year, .month, .day], from: runningDate) // The repeat loop while runningDate = endDate { repeatArray.append(runningDate) // add increment to runningDate switch repeats { case 1 : runningDate = calendar.date(byAdding: .day, value: 1, to: runningDate)! // ?? endDate case 2 : runningDate = calendar.date(byAdding: .day, value: 7, to: runningDate)! case 3 : runningDate = calendar.date(byAdding: .month, value: 1, to: runningDate)! // you increment the month default: break } } Now, it is up to you to fine tune this. Wish you best. And don't forget to close the thread.
Topic: App & System Services SubTopic: General Tags:
Feb ’21
Reply to TableView relsoaddata from textField on the same viewController with TableView
You're new here, normal you have a few things to learn. To format, just select the code section and apply the tool: func addFeedbacks(message: String,taskId: String,atype: Int) { if currentUser != nil { let feed = PFObject(className: "Feedback") feed["TaskId"] = taskId feed["TaskFeedback"] = message feed["UserNameFrom"] = currentUser?.username! feed["AType"] = atype feed.saveInBackground() } } Please show saveInBackground() Maybe you could call reload() inside saveInBackground(), but I need to see what the func is to confirm.
Topic: App & System Services SubTopic: Core OS Tags:
Feb ’21
Reply to Best practice for storing repeating dates in CoreData
To avoid the risk of infinite loop, you could adapt slightly: var stopNow = false // The repeat loop while runningDate = endDate && !stopNow { // If end == start, we have just one day repeatArray.append(runningDate) // add increment to runningDate switch repeats { case 1 : runningDate = calendar.date(byAdding: .day, value: 1, to: runningDate)! // ?? endDate case 2 : runningDate = calendar.date(byAdding: .day, value: 7, to: runningDate)! case 3 : runningDate = calendar.date(byAdding: .month, value: 1, to: runningDate)! // you increment the month default: stopNow = true } }
Topic: App & System Services SubTopic: General Tags:
Feb ’21
Reply to Loop over two arrays with different length
The loop will finish when arrayOfItems is finished. But it is a dynamic array in the sense that sometimes n could be 100 or 1000. What is the problem with the proposed solution ? It will work in all cases. n can be 100 or 1000, it will work the same. Using this approach I will have to create if statements every tens. So, it's not generic for any n numbers Effectively, as you don't know if n is 10 or 10 000 it is unpractical solution. You are just hard coding a computed solution. Don't do this.
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’21