I want to update XCode version.
But while updating I receive several compiler errors. The are the same as this:
id<MyProtocol> objectToDelete = group[index.unsignedIntegerValue];
Expected method to read array element not found on object of type 'id'
id<MyProtocol> _Nonnull group
@protocol MyProtocol <NSObject>
@property (copy, nonatomic) NSString* name;
@property (copy, nonatomic) NSString* id;
@property (copy, nonatomic) NSString* internalType;
@property (strong, nonatomic) NSMutableArray<id<SomeAnotherProtocol>>* objects;
- (instancetype)initWithObject:(MyProtocol*)object;
// Search
- (BOOL)isContainsObjectWithID:(NSString*)myID;
- (NSUInteger)indexForObjectID:(NSString*)myID;
- (id<SomeAnotherProtocol>)objectWithID:(NSString*)myID;
- (NSString*)groupID;
@end
This error appears only on XCode 9.3 version.
Does id<MyProtocol> objectToDelete = ((NSArray *) group)[index.unsignedIntegerValue];
the only solution?
try this one: [group objectAtIndexedSubscript:idx]
First, I'm assuming that
group
is not actually anNSArray
, but is in fact:This says that
group
is "some object that conforms toMyProtocol
". Nothing inMyProtocol
says that this object can be subscripted. If you want it to be subscriptable by indexes, then you need to say this in the protocol:And you of course need to implement
objectAtIndexedSubscript:
in anything that conforms (but this seems to already be the case, since it works when you cast it).