What does @NSManaged do?

后端 未结 3 1152
心在旅途
心在旅途 2021-01-30 06:55

I have encountered this keyword in various occasions. I kind of know what it\'s suppose to do. But I really want a better understanding of it.

What I noticed about

相关标签:
3条回答
  • 2021-01-30 07:13

    Yes, it kinda really acts like @dynamic -- technically it might be identical even. Semantically there is a slight difference:

    @dynamic says 'compiler, don't check if my properties are also implemented. There might be no code you can see but I guarantee it will work at runtime'

    @NSManaged now says 'compiler, don't check those properties as I have Core Data to take care of the implementation - it will be there at runtime'

    so you could even say: @NSManaged is syntactic sugar that is a more narrow version of dynamic :)


    https://github.com/KyoheiG3/DynamicBlurView/issues/2
    here someone even used @NSManaged without CD because he wanted the @dynamic behaviour

    0 讨论(0)
  • 2021-01-30 07:23

    In the apple docs, for Custom Managed Object Class, they quote properties example like... To me it seems there is no difference, I have used @dynamic in objective C, it seems @NSManaged is the replacement in Swift.

    0 讨论(0)
  • 2021-01-30 07:29

    Above mentioned answers are right. Here is my understanding.

    @NSManaged indicates that the variables will get some values when we run the app. Coredata automatically creates getter and setter for such props. It silences the compiler for warnings.

    NSmanaged is subclass of NSObject. @NSManaged means extra code will be given to these props at runtime. It tracks the changes made to those properties.

    0 讨论(0)
提交回复
热议问题