YapDatabase icon indicating copy to clipboard operation
YapDatabase copied to clipboard

YapDatabaseRelationshipNode protocol causes strange crash in YapDatabaseCloudKitRecordHandler

Open uthiel opened this issue 9 years ago • 4 comments

Adding the <YapDatabaseRelationshipNode> protocol to one of my classes causes a crash in YapDatabaseCloudKitRecordHandler, which is more a less an exact copy of the CloudKitTodo example. The crash happens near the end of the block when the newly created CKRecord is populated with the properties of the database object:

		for (NSString *cloudKey in cloudKeys)
	{
		id cloudValue = [object cloudValueForCloudKey:cloudKey];
		[record setObject:cloudValue forKey:cloudKey];
	}

and the code tried to set the property superclass of the CKRecord to TSItem, which btw is the superclass of the object the block is handling. The resulting error message looks like this:

'Objects of class TSItem cannot be set on CKRecord'

Prior to conforming to <YapDatabaseRelationshipNode>, cloudKeys would look like this:

textData,
collectionUUID,
name

which are the properties of the class that are supposed to be synced with CloudKit, but after adding the protocol, cloudKeys suddenly looks like this:

hash,
superclass,
textData,
collectionUUID,
debugDescription,
description,
name

Does anyone know what's going on?

uthiel avatar Nov 22 '16 19:11 uthiel

I found out that yapDatabaseRelationshipEdges will get called although <YapDatabaseRelationshipNode> is commented out. While that doesn't cause a crash, it somehow messes up the database and makes objects vanish from the local cache, but strangely not from iCloud.

As soon as I activate <YapDatabaseRelationshipNode>, the app crashes on creating a new object, as explained above. Strange isn't it?

uthiel avatar Nov 22 '16 21:11 uthiel

I found the root cause of this crash:

In YapDatabaseRelationshipNode.h: @protocol YapDatabaseRelationshipNode <NSObject> Since iOS 8, @protocol NSObject declares some methods as properties:

hash,
superclass,
debugDescription,
description,

Conforming to the NSObject protocol makes class_copyPropertyList in MyDatabaseObject.m add those 4 properties.

Solution: In YapDatabaseRelationshipNode.h: change @protocol YapDatabaseRelationshipNode <NSObject> to @protocol YapDatabaseRelationshipNode

Do I need to issue a pull request for this?

uthiel avatar Dec 08 '16 06:12 uthiel

Can someone (maybe Robbie) please comment on why this issue hasn't been commented on yet?

uthiel avatar Dec 16 '18 21:12 uthiel

the code tried to set the property superclass of the CKRecord to TSItem

Haha. That's not going to work...

Since iOS 8, @protocol NSObject declares some methods as properties:

Oh wow. That's good to know. Great find !!!

Do I need to issue a pull request for this?

If you could that would be great. All 4 items in that list (hash, superclass, debugDescription, & description) should always be filtered from monitoring. We can probably filter this in MyDatabaseObject.m.

robbiehanson avatar Dec 17 '18 01:12 robbiehanson