是否可以使用 PFUser 的两个子类?
Is it possible to use two subclasses of PFUser?
我在我的应用程序中使用 parse.com iOS 框架。我的 User
对象是标准解析 PFUser
的子类。我的应用程序中有两种截然不同的用户:学生和教师。我厌倦了遍布我的代码的大量 if (user.isTeacher) {...} else {...}
语句,它看起来像是多态性的完美目标。问题是:解析框架如何在我的查询中确定它应该 return Teacher
还是 Student
PFUser
的子类?实际上有什么方法可以让 PFUser
的两个子类带有解析?还有其他想法吗?
不可能,至少对于当前版本的 Parse SDK (1.7.1),因为 registerSubclass
方法在第二个子类中崩溃并显示消息:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to register both
AnotherUser and User as the native PFObject subclass of _User. Cannot
determine the right class to use because neither inherits from the
other.'
我在我的应用程序中使用 parse.com iOS 框架。我的 User
对象是标准解析 PFUser
的子类。我的应用程序中有两种截然不同的用户:学生和教师。我厌倦了遍布我的代码的大量 if (user.isTeacher) {...} else {...}
语句,它看起来像是多态性的完美目标。问题是:解析框架如何在我的查询中确定它应该 return Teacher
还是 Student
PFUser
的子类?实际上有什么方法可以让 PFUser
的两个子类带有解析?还有其他想法吗?
不可能,至少对于当前版本的 Parse SDK (1.7.1),因为 registerSubclass
方法在第二个子类中崩溃并显示消息:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to register both AnotherUser and User as the native PFObject subclass of _User. Cannot determine the right class to use because neither inherits from the other.'