Posted on 

Introspection when learning CoreData

请注意

技术类文章并不一定会进行中文翻译。如此文章无中文翻译,请移步英文界面阅读。

Attention

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.


本站由 @deskside 使用 Stellar 主题创建。
This site is created with love by @deskside , powered by Hexo theme Stellar.
本博客所有文章除特别声明外,均采用 署名-非商业性使用-相同方式共享 4.0 国际 许可协议,转载请注明出处。
All articles, unless otherwise stated, are in CC BY-NC-SA 4.0 license agreement. Please indicate the source when reproduced.
由于中国大陆网络政策的限制,部分图片可能无法顺利显示。
Due to the restrictions of Chinese mainland’s network policy, some pictures may not be displayed smoothly.