Compiler error “expected method not found” when using subscript on NSArray

后端 未结 7 2027
悲哀的现实
悲哀的现实 2020-11-29 04:45

I wrote this simple code to try out the new Objective-C literal syntax for NSArrays:

NSArray *array = @[@"foo"];
NSLog(@"%@",         


        
7条回答
  •  囚心锁ツ
    2020-11-29 05:10

    I'm adding this because this is a common error that still exists in Xcode as of 7/2015 and it's not easy to figure out how to resolve it.

    I received this error when attempting to call a method on an object without having created an instance of the object. My solution was to create an instance of the object, then call the method on the property on the instance of that object.

    Example: What didn't work: [self methodCall:arrayItem] (see full example below)

    [self tappedUser:self.activities[indexPath.row].followItem.user.givenName];
    

    What fixed it: ObjectClass newObject = arrayItem; [self methodCall:newObject] (see full example below)

    FollowActivityItem *followItem = self.activities[indexPath.row];
    [self tappedUser:followItem.user.givenName];
    

提交回复
热议问题