Question

THis is my class

@interface BGImageBookController () <BGPageViewControllerDelegateProtocol>
@property (strong, nonatomic) IBOutlet UIPageViewController *pvc;

It contains a property called pvc. pvc is NOT a read only property.

However, BGImageBookController also supports a protocol

@protocol BGPageViewControllerDelegateProtocol <NSObject>

@property (readonly,nonatomic) UIPageViewController * pvc;
-(void)reDrawEverything;
@end

In the protocol, pvc is a read only property. That's because the PageViewControllerDelegate does not ever need to change pvc.

Well this causes conflicts.

I got: /business/Dropbox/badgers/BadgerNew/BGImageBookController.m:30:17: Readonly IBOutlet property when auto-synthesized may not work correctly with 'nib' loader

I tried to fix that by adding

@dynamic pvc;

Then I got this run time error

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<BGImageBookController 0x1e0df340> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key pvc.'
*** First throw call stack:
(0x3120e2a3 0x38eb397f 0x3120df99 0x31a7b1d9 0x31a76f2b 0x3119461b 0x331b331d 0x331b2b9b 0x330ab03d 0x3303546d 0x14b7c9 0x14b8fd 0x14b9b1 0xc8eeb 0xc705f 0xc71a7 0x33133d89 0x330fb3f5 0x332e8a39 0x3301f82f 0x3301e293 0x330291e7 0x33028db3 0x33016801 0x3301611b 0x34d195a3 0x34d191d3 0x311e3173 0x311e3117 0x311e1f99 0x31154ebd 0x31154d49 0x34d182eb 0x3306a301 0x37299 0x37220)
libc++abi.dylib: terminate called throwing an exception

So basically BGImageBookController supports the property pvc in 2 ways.

It has an IBOutlet property called pvc It supports a protocol that requires a read only property called pvc.

I thought everything should work fine. After all, having a non read only property means also supporting -(UIPageViewController *) pvc;

Of course I can just change the variable name in protocol and reimplement that in my class

-(UIPageViewController *)   pvc1
{
    return self.pvc;
}

But I think I should be able to get this even without doing that. After all, the class already supports

-(UIPageViewController *)   pvc

Namely it's a property named pvc whose type is UIPageViewController

Was it helpful?

Solution

It seems that only the compiler is confused about the two declarations of the pvc property and emits a warning.

Your code runs without problems, and you don't have to add a @dynamic or @synthesize statement.

You can suppress the warning in the implementation block with

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreadonly-iboutlet-property"
@implementation BGImageBookController
#pragma clang diagnostic pop

Note that the warning is shown only if you declare the outlet in a class extension. If you move the outlet declaration to the public interface in "BGImageBookController.h", the warning also goes away.

This looks like a compiler bug and you could file a bug at bugreporter.apple.com.

OTHER TIPS

Define your property as:

@property (readwrite, strong, nonatomic) IBOutlet UIPageViewController *pvc;

And fully synthesise it:

@synthesize pvc = _pvc;

Currently you're telling the compiler that someone else will be synthesising the accessor methods and that isn't true so at runtime you end up trying to call a method that doesn't exist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top