12

The header file looks like:

enum RatingsEnum
{
    userRating,
    criticRating,
};

@interface SFMovie : NSObject

- (NSNumber *)getRating:(NSDictionary *)movieDic :(enum RatingsEnum) rating;

@end

How can I use this method getRating? I am not sure how to pass the enum. My calling code:

- (void) testGetCriticRatingMethod{

    NSMutableDictionary *ratingDictionary = [[NSMutableDictionary alloc]init];
    [ratingDictionary setObject:@"Certified Fresh" forKey:@"critics_rating"];
    [ratingDictionary setObject:@"70" forKey:@"critics_score"];
    [ratingDictionary setObject:@"Certified Fresh" forKey:@"audience_rating"];
    [ratingDictionary setObject:@"87" forKey:@"audience_score"];
    SFMovie *movie = [[SFMovie alloc]init];
    enum RatingsEnum ratings;
    NSInteger userRating = [movie getRating:ratingDictionary rating:userRating];
}

This produces the following warning: No visible @interface for 'SFMovie' declares the selector 'getRating:rating:'

Can somebody guide me to a good enum tutorial? Thank you all.

2
  • This really doesn't have anything to do with enums. It's just about naming methods in general. Commented Jan 21, 2014 at 0:00
  • Yes, thank you. I did not spend enough time debugging before asking the question here :(. I saw the mistake right after putting the question on stackoverflow :( Commented Jan 21, 2014 at 0:01

2 Answers 2

21

Change

 - (NSNumber *)getRating:(NSDictionary *)movieDic :(enum RatingsEnum) rating;

to

 - (NSNumber *)getRatingWithDictionary:(NSDictionary *)movieDic ratingEnum:(enum RatingsEnum) ratingEnum;

Change

 enum RatingsEnum ratings;
 NSInteger userRating = [movie getRating:ratingDictionary rating:userRating];

to

 enum RatingsEnum ratings = userRating;
 NSNumber *ratingFromUser = [movie getRatingWithDictionary:ratingDictionary ratingEnum:ratings];
Sign up to request clarification or add additional context in comments.

Comments

1

This has nothing to do with the enum, or the type of the parameter at all. Your syntax is simply wrong. The name of the method as declared is getRating::. A correct call looks like

[movie getRating:ratingDictionary :userRating];

Add a label to the second parameter

- (NSNumber *)getRating:(NSDictionary *)movieDic ofType:(enum RatingsEnum)rating;

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.