objective-c - 无法识别的选择器 : [NSSQLToMany _setInverseManyToMany:]

标签 objective-c ios core-data restkit nsmanagedobject

这是我遇到过的最奇怪的错误,仅仅是因为我在任何地方都找不到关于它的任何信息。

背景:

我有一个应用程序使用映射到核心数据的 RestKit(当前主控)。我正在使用自定义映射提供程序(RKObjectMappingProvider 的子类)。这会生成我需要的所有映射,类似于 RKGithub项目。

我的一些对象具有多对多关系,因此我必须在设置其他关系后(在映射提供程序中)注册一些关系以避免无限递归。 ( friend 有_很多 friend 有_很多 friend ...)

当应用程序运行和 RestKit 配置自身时,此行发生错误(在 RKManagedObjectStore.m 中)

_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:_managedObjectModel];

我无法进入“initWithManagedObjectModel:”方法。我得到的唯一信息是日志中的这个异常:

-[NSSQLToMany _setInverseManyToMany:]: unrecognized selector sent to instance 0xcc78890

我不知道是什么原因造成的,也不知道如何解决。我找不到任何关于它的文档,甚至找不到以前遇到过这个问题的人。我所能找到的只是这个 iOS 框架的转储:

public struct NSSQLManyToMany : IEquatable<NSSQLManyToMany> {
        internal NObjective.RuntimeObject Handle;
        public static readonly RuntimeClass ClassHandle = CoreDataCachedClasses.NSSQLManyToMany;
        public static implicit operator IntPtr( NSSQLManyToMany value ) {
            return value.Handle;
        }
        public static implicit operator NObjective.RuntimeObject( NSSQLManyToMany value ) {
            return value.Handle;
        }
        public override bool Equals( object value ) {
            var compareTo = value as NSSQLManyToMany?;
            return compareTo != null && Handle == compareTo.Value.Handle;
        }
        public bool Equals( NSSQLManyToMany value ) {
            return Handle == value.Handle;
        }
        public static bool operator ==( NSSQLManyToMany value1, NSSQLManyToMany value2 ) {
            return value1.Handle == value2.Handle;
        }
        public static bool operator !=( NSSQLManyToMany value1, NSSQLManyToMany value2 ) {
            return value1.Handle != value2.Handle;
        }
        public NSSQLManyToMany( IntPtr value ) {
            this.Handle = new RuntimeObject( value );
        }
        public static NSSQLManyToMany alloc() {
            return new NSSQLManyToMany( ClassHandle.InvokeIntPtr( Selectors.alloc ) );
        }
        unsafe public NObjective.RuntimeObject inverseColumnName() {
            RuntimeObject ___occuredException;
            var ___result = NativeMethods.inverseColumnName( Handle, CachedSelectors.inverseColumnName, out ___occuredException, 0 );
            if( ___occuredException != RuntimeObject.Null ) throw RuntimeException.Create( ___occuredException ); 
            return new NObjective.RuntimeObject( ___result );
        }
        unsafe public NObjective.RuntimeObject inverseManyToMany() {
            RuntimeObject ___occuredException;
            var ___result = NativeMethods.inverseManyToMany( Handle, CachedSelectors.inverseManyToMany, out ___occuredException, 0 );
            if( ___occuredException != RuntimeObject.Null ) throw RuntimeException.Create( ___occuredException ); 
            return new NObjective.RuntimeObject( ___result );
        }
        unsafe public bool isMaster() {
            RuntimeObject ___occuredException;
            var ___result = NativeMethods.isMaster( Handle, CachedSelectors.isMaster, out ___occuredException, 0 );
            if( ___occuredException != RuntimeObject.Null ) throw RuntimeException.Create( ___occuredException ); 
            return ___result;
        }
        unsafe public bool isReflexive() {
            RuntimeObject ___occuredException;
            var ___result = NativeMethods.isReflexive( Handle, CachedSelectors.isReflexive, out ___occuredException, 0 );
            if( ___occuredException != RuntimeObject.Null ) throw RuntimeException.Create( ___occuredException ); 
            return ___result;
        }
        private static class NativeMethods {
            [DllImport(Runtime.InteropLibrary, EntryPoint = "objc_msgSend_eh2")]
            public static extern IntPtr inverseColumnName( RuntimeObject ___object, Selector ___selector, out RuntimeObject ___occuredException, int ___stackSize );
            [DllImport(Runtime.InteropLibrary, EntryPoint = "objc_msgSend_eh2")]
            public static extern IntPtr inverseManyToMany( RuntimeObject ___object, Selector ___selector, out RuntimeObject ___occuredException, int ___stackSize );
            [DllImport(Runtime.InteropLibrary, EntryPoint = "objc_msgSend_eh2")]
            public static extern bool isMaster( RuntimeObject ___object, Selector ___selector, out RuntimeObject ___occuredException, int ___stackSize );
            [DllImport(Runtime.InteropLibrary, EntryPoint = "objc_msgSend_eh2")]
            public static extern bool isReflexive( RuntimeObject ___object, Selector ___selector, out RuntimeObject ___occuredException, int ___stackSize );
        }
        static internal class CachedSelectors {
            public static readonly Selector inverseColumnName = "inverseColumnName";
            public static readonly Selector inverseManyToMany = "inverseManyToMany";
            public static readonly Selector isMaster = "isMaster";
            public static readonly Selector isReflexive = "isReflexive";
        }
    }

这很明显似乎有一个二传手:

public NSSQLManyToMany( IntPtr value ) {
        this.Handle = new RuntimeObject( value );
    }

有什么想法吗?

编辑: 我应该补充一点,我已经尝试了所有“简单”的解决方案。从 sim 卡中删除应用程序不起作用。

我怀疑这可能是因为我有一个实体与同一(不同)实体有两个“拥有并属于许多”关系。但我不明白为什么这会成为一个实际问题。

最佳答案

刚想通了!

我在一个实体上有两个指向另一个实体的关系,它们无意中具有相同的逆。

举例说明:

Part:
   has many (Car*)cars, inverse parts
   has one (Car*)deliveryTruck, inverse parts 

有点做作,但想法是存在的。我不得不将第二个 parts 更改为其他一些属性。

希望这会帮助其他人处理相同的神秘错误消息。你会期望 clang 会警告你这样的事情! (如果你根本没有逆函数,它就够吓人的了)。

关于objective-c - 无法识别的选择器 : [NSSQLToMany _setInverseManyToMany:],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12885611/

相关文章:

ios - 为对象双属性排序数组

iOS UITableView : changing background color of table overrides background color of cells

ios - 当状态栏也一样时,如何使 iOS 7 状态栏中的绿色电池图标(手机正在充电时)消失?

ios - PopupViewController 将 null 返回给 ViewController

ios - 如何使用魔法记录将两个 NSMutableArray 中的数据保存到单个实体中

ios - 核心数据添加关系作为唯一约束 - iOS

ios - 解析 XML 数据 objective-c

ios - 为什么我的 MKPointAnnotation 在 View 加载时没有出现?

ios - 将 UISwitch 状态从一个 View Controller 传递到另一个 View Controller

objective-c - NSFetchedResultsController、sectionNameKeyPath 和没有数据的日期部分