UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Coredata svind in sequence

Forums > SwiftUI

Hello,

I would like to save a text in coredata but in a sequence of questione.

Question 1 Input Text Button Save -->

Question 2 Input Text Button Save -->

.... 3..4...5

witch strategy you suggest to manage the sequence and to save the text in the same records?

Thanks

2      

@Bnerd  

I guess you should have an Entity i.e. Question, that has two attributes questionNumber: Int questionText: String

If you are not planning on deleting questions in the future, you could just create each new question by providing a questionNumber as per the Question.count i.e. questionNumber = Question.count + 1

if you plan to be able to delete questions the above will not work, but you could add a questionDateCreated: Date attribute in your Question and sort your questions. This way you could re-assign the questionNumber depending on the sorting.

Just ideas :) I hope they will help you.

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.