0

Prior to xcode 9.3, the following code snippet worked fine:

CKRecord *thePublicGameRecord;
...
//the record value, thePublicGameRecord[KEY_PLAYERSTATES], is set to a NSMutableArray, the size of which is based on the number of players in the game.
...

for (int i = 1; i <= max_number_of_players; i++)
{
    NSNumber *playerState - thePublicGameRecord[KEY_PLAYERSTATES][i];
    ...
}

Since upgrading to xcode 9.3, this line:

NSNumber *playerState - thePublicGameRecord[KEY_PLAYERSTATES][i];

Now gives a build error:

Expected method to read array element not found on object of type '__kindof id < CKRecordValue > _Nullable'

and I have to unwrap the underlying array like so:

NSMutableArray *statesArray = thePublicGameRecord[KEY_PLAYERSTATES];
playerStatus = statesArray[i];

That's not the end of the world, but I preferred the original approach.

I've read many other questions reporting this error, but they all look like different scenarios (incorrect definitions of custom protocols, mismatched variable types, and/or issues prior to the release of xcode 4.5).

Expected method to read array element not found on object of type 'id<ProtocolName>'

Compiler error "expected method not found" when using subscript on NSArray

expected method to read dictionary element not found on object of type "NSDateFormatter*"

Since this code has been working for more than a year, I believe the error results from some change in enforcement. In xcode 9.3, does this stem from some new/changed config setting, and can I fix it?

Thunk
  • 4,099
  • 7
  • 28
  • 47
  • How do you declare CKRecord ? – battlmonstr Apr 08 '18 at 20:35
  • @battlmonstr `CKRecord` is from CloudKit. – rmaddy Apr 08 '18 at 20:39
  • ` CKRecord *thePublicGameRecord = nil; id value = thePublicGameRecord[@"something"]; NSNumber *item = value[123]; NSLog(@"%@", item); NSNumber *valueItem2 = thePublicGameRecord[@"something"][123]; NSLog(@"%@", valueItem2); ` this WFM without any warnings. Are you sure you import Foundation? It needs to find that every "id" has "objectForKey:" method or something. – battlmonstr Apr 09 '18 at 15:38
  • @battlmonstr I do have foundation.h. Your code snippet generates the same "expected method..." build error on the two lines where you used "123" as an index. So that does suggest that it's config-related, but still not sure what. – Thunk Apr 09 '18 at 20:38
  • Duplicate of https://stackoverflow.com/questions/11425976/compiler-error-expected-method-not-found-when-using-subscript-on-nsarray ? – battlmonstr Apr 10 '18 at 20:49
  • That’s the middle link I cited above. Since it talks about new functionality in IOS6 and since this was working for me in IOS 11 before upgrading xcode, it doesn’t seem to be a solution for me. – Thunk Apr 11 '18 at 05:33

0 Answers0