Bird
0
0

You want to save a new 'Task' entity with a 'title' attribute using Core Data. Which sequence correctly saves the data?

hard📝 Application Q15 of 15
iOS Swift - Local Data Persistence
You want to save a new 'Task' entity with a 'title' attribute using Core Data. Which sequence correctly saves the data?
ACreate Task object, set title, call URLSession to save
BCreate Task object, set title, call print() to save
CCreate Task object, set title, call context.save() inside do-catch
DCreate Task object, set title, no need to save context
Step-by-Step Solution
Solution:
  1. Step 1: Create and set attributes on Task object

    Instantiate Task with context and assign the title attribute.
  2. Step 2: Save context with error handling

    Call context.save() inside a do-catch block to persist changes safely.
  3. Final Answer:

    Create Task object, set title, call context.save() inside do-catch -> Option C
  4. Quick Check:

    Save Core Data changes with context.save() [OK]
Quick Trick: Always call context.save() inside do-catch to persist data [OK]
Common Mistakes:
  • Forgetting to call context.save() after changes
  • Using print or network calls to save data
  • Ignoring error handling when saving

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes