跳过抽象实体的子实体,仅以编程方式实现子类? [英] Skip subentity of abstract entity and just implement subclasses programatically?

查看:58
本文介绍了跳过抽象实体的子实体,仅以编程方式实现子类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个核心数据抽象实体,该实体由一个类支持,该类为我创建和操纵其实例的许多具体[sub]实体的子类。子类中的属性,关系或属性没有不同。我只是重载方法的实现。因此,然后再设置子类和父实体,则每个子实体的xcdatamodeld均为空。

I have a core data abstract entity which is backed by a class that's subclassed for many concrete [sub]entities that I create and manipulate instances of. No attributes or relationships or properties are different in the subclasses. I'm just overriding method implementations. So other then setting the subclass and parent entity, the xcdatamodeld is empty for each subentity.

如果xcdatamodeld的子实体中没有唯一的属性或关系,则我我创建了许多代码,是否可以在抽象超实体类中创建一些代码来处理核心数据子实体注册?

If there are no unique properties or relationships in the subentities in xcdatamodeld, and I'm creating quite a number of them, is there some code that I could create in the abstract superentity class to handle the core data subentity registration?

我要寻找的是一些合理代码,这些代码使我可以为每个新的子实体创建一个.h / .m(子类抽象实体(它是NSManagedObject的子类),并跳过了xcdatamodeld中的+ entity,编辑名称,添加类,声明父实体的看似重复和混乱的工作。这可行且合理吗?还是在类实现之外进行神秘的程序化ManagedObjectModel编辑工作?

What I'm looking for is some reasonable code that lets me just create a .h/.m for each new subentity (which subclasses the abstract entity, which subclasses NSManagedObject), and skip seemingly duplicate and cluttering work in xcdatamodeld of +entity, edit name, add class, declare parent entity. Is this feasible and reasonable? Or do I go down a rabbit hole of arcane programmatic managedObjectModel editing outside of my class implementations?

[edit]要添加有关为什么使用子类的背景。一个-每个子类创建一个不同的子实体树。两个-每个子类以不同的方式组装其数据以传递给视图。也就是说,它们都具有相同的字符串属性,但是每个子类呈现的attributedStringForTitle都不同于下一个。

[edit] To add background about why subclasses. One-- each subclass creates a different tree of child entities. Two-- each subclass assembles its data differently for passing to views. ie they all have the same string properties, but each subclass might present an attributedStringForTitle differently than the next.

推荐答案

可能是离您最近的可以通过使用 mogenerator 获得。您也许可以脚本化对数据模型的更改,但是除非您要创建很多类,否则它可能不会节省您的时间。

Probably the closest you will get is by using mogenerator. You may be able to script changes to the data model, but unless you're going to create lots of classes then it likely won't save you time.

这篇关于跳过抽象实体的子实体,仅以编程方式实现子类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆