Introspection when learning CoreData
技术类文章并不一定会进行中文翻译。如此文章无中文翻译,请移步英文界面阅读。
This is a learning note, which means that there may be mistakes and misunderstanding in it. You are more than welcome to correct me by commenting below.
After 2 days of trying to figure out a simple CoreData
problem when building EmoDiary app, I finally solve it yesterday night. Introspections are made here to help me study more efficiently in th future.
Key words are incorrect when Googling
Due to not fully understanding the structure of Core Data and some basic Swift syntax, I struggled googling blindly resulting in no related answers.
What I was trying to do is to write a piece of codes that can add one of Emotions (Entity-A) to one attribute of Record (Entity-B).
But when I type key words to search online, I type in:
- add one entity to another core data (❌)
- core data add attribute to another entity (❌)
- …
This is incorrect since these key words don’t even touch the essence of my need.
I didn’t even figure out the relationships between these two entities. They are one to many, not one to one. One Emotion can be assigned to many different Records, while one Record should only have one Emotion.
So, any blog post or YouTube video considering core data one to many
shall have the resolution I need.
Finally, after typing in the following words, I find the tutorial video I need.
- core data one to many (✅)
Not knowing what to code but still coding
It’s a bad habit that I didn’t even draft an outline when I started coding, quite like a headless chicken.
Knowing where to go and how to go is a solid fundamental rule for high productivity. Always sort out what you want to do before actually taking the first step.
Bad names
I kind of name my core data badly.
For each record input by user, I call it EmoEachTime
. It is too long and not specific enough. Actually, Record
is just fine.
Not enough patience
Since I am a native Chinese speaker, I am not so fluent in English reading, especially when it come to CS along with too many terms.
Be patient. Read docs, watch tutorial videos and study code examples given by Apple.