0
  1. How do I get rid of the warning and not use [@[] mutableCopy]:

//Incompatible pointer types assigning to 'NSMutableArray *' from 'NSMutableArray *'

@protocol Coordinatorable <NSObject>

@property (nonatomic, strong, readonly) UINavigationController *presenter;
@property (nonatomic, strong, readonly) NSMutableArray<Coordinatorable>*childCoordinators;

@end


self.childCoordinators = [[NSMutableArray alloc] init]; //Incompatible pointer types assigning to 'NSMutableArray<Coordinatorable> *' from 'NSMutableArray *'
self.childCoordinators = [@[] mutableCopy]; //works without issue
0

2 Answers 2

2

I believe the cause of your issue is in how you declare your property. The line:

@property (nonatomic, strong, readonly) NSMutableArray<Coordinatorable>*childCoordinators;

should be:

@property (nonatomic, strong, readonly) NSMutableArray<id<Coordinatorable>>*childCoordinators;

The use of id<SomeeProtocol> is what is needed when referencing objects that conform to the protocol.

Sign up to request clarification or add additional context in comments.

Comments

1

How do I get rid of the warning and not use [@[] mutableCopy]:

Cast the result:

self.childCoordinators = (NSMutableArray<Coordinatorable>*)[[NSMutableArray alloc] init];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.