Rob Sanders
Rob Sanders

Reputation: 5347

Warning assigning to _Nullable from incompatible type _Nonnull, but changing modifier does nothing

I have a protocol that defines the following method:

- (MyObj * _Nonnull)initWithManagedObject:(NSManagedObject * _Nonnull)managedObject dataManager:(id<DataManagerProtocol> _Nonnull)dataManager;

The class that implements it has a property:

@property (nonatomic, weak, readonly) id<DataManagerProtocol> dataManager;

The implementation of the method is like:

- (MyObj *)initWithManagedObject:(NSManagedObject *)object dataManager:(id<RHDataManagerProtocol>)dataManager
{
    // TEST
    self = [super init];
    if (self) {
        // Both the following lines cause the warning.
        // Changing nullability has no effect.
        self.dataManager = dataManager;
        //_dataManager = dataManager;
    }
    return self;
}

This is the exact warning:

Assigning to 'id _Nullable' from incompatible type '__strong id _Nonnull'

Changing the nullability doesn't do anything.

EDIT: I have the following class extension in the .m file:

@interface MyObj ()

@property (nonatomic, weak) id<DataManagerProtcol> dataManager;

@end

Upvotes: 1

Views: 1369

Answers (2)

Tim
Tim

Reputation: 1616

~.delegate = (id)self;

Can fix this.

Upvotes: 0

Rob Sanders
Rob Sanders

Reputation: 5347

This turned out to be an Xcode bug. When I next started up my project (after restarting the computer) the error resolved itself.

Upvotes: 0

Related Questions