BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

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

   

@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.

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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

Reply to this topic…

You need to create an account or log in to reply.

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.