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

时间:2012-10-14 19:13:53

标签: objective-c ios core-data restkit nsmanagedobject

这是我曾经遇到的最奇怪的错误,仅仅是因为我无法在任何地方找到任何信息。

背景:

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

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

当应用程序运行且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卡中删除应用程序不起作用。

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

1 个答案:

答案 0 :(得分:1)

刚想出来了!

我在一个指向另一个实体的实体上有两个关系,他们无意中有相同的反转。

举例说明:

Part:
   has many (Car*)cars, inverse parts
   has one (Car*)deliveryTruck, inverse parts 
有点做作,但想法就在那里。我不得不将第二个parts更改为其他属性。

希望这可以帮助其他人使用相同的神秘错误消息。你希望clang警告你这样的事情! (如果你根本没有反转的话,那就太疯狂了。)