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.
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];
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With