NSProxy incompatible pointer types

68 Views Asked by At

I have an NSProxy subclass called EBManagedObject and an NSObject subclass called EBObject. EBManagedObject is initialized with a guid that is used to retrieve an EBObject from EBObjectRepository. EBManagedObject will forward any message sent to it to its EBObject, except for some restricted messages, in which case it will throw an exception. So wherever you can use an EBObject you can use an EBManagedObject. My problem is that Xcode doesn't understand this and gives me an incompatible pointer types warning when trying to do the following:

EBObject *object = [[EBManagedObject alloc] initWithGuid:guid];

It's simple enough to fix:

EBObject *object = (EBObject *)[[EBManagedObject alloc] initWithGuid:guid];

But I am wondering if there is any way to make Xcode consider EBObject and EBManagedObject compatible pointer types?

I know I could create a protocol that both of them implement and do something like:

id<EBObject> object = [[EBManagedObject alloc] initWithGuid:guid];

But I have good reasons not to do that.

By the way, all the class names are made up. My actual scenario is more complex, so I made a simplified example to explain my problem.

0

There are 0 best solutions below