2009-11-10 2 views
0

Objective-CComment puis-je me débarrasser de cet avertissement de type de conflit?

Conflict types for '-(NSInteger)amountYear:(NSInteger)searchYear Month:(NSInteger)searchMonth' 

Comment puis-je me débarrasser de cet avertissement?

.m

#import "MyAppDataController.h" 
#import "MyApplicationData.h" 

@implementation MyAppDataController 

@synthesize appdata; 

static id _instance = nil; 

+ (id)instance 
{ 
    @synchronized(self) { 
    if (!_instance) { 
     _instance = [[MyAppDataController alloc] init]; 
    } 
    } 
    return _instance; 
} 

+ (id)allocWithZone:(NSZone*)zone 
{ 
    @synchronized(self) { 
    if (!_instance) { 
     _instance = [super allocWithZone:zone]; 
     return _instance; 
    } 
    } 
    return nil; 
} 

- (id)copyWithZone:(NSZone*)zone 
{ 
    return self; 
} 

- (id)retain 
{ 
    return self; 
} 

- (unsigned)retainCount 
{ 
    return UINT_MAX; 
} 

- (void)release 
{ 
} 

- (id)autorelease 
{ 
    return self; 
} 

-(void)loadData{ 
    NSData* data = [[NSMutableData alloc]initWithContentsOfFile:[self dataFilePath]]; 
    NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData:data]; 
    appdata = [unarchiver decodeObjectForKey:DATAKEY]; 
    [unarchiver finishDecoding]; 
    [unarchiver release]; 
    [data release]; 
    if (!appdata) { 
    appdata = [[MyApplicationData alloc]init]; 
    } 
    if (!appdata.categories) { 
    appdata.categories = [[NSMutableArray alloc]init]; 
    } 
    if (!appdata.items) { 
    appdata.items = [[NSMutableArray alloc]init]; 
    } 
    NSLog(@"%@", appdata.items); 
    NSLog(@"%@", appdata.categories); 
} 

-(void)addAppDataItemPrice:(NSString*)price itemCategory:(NSString*)category itemDate:(NSDate*)date{ 
    NSInteger index = -1; 
    if ([appdata.categories count] != 0) { 
    index = [appdata.categories indexOfObject:category]; 
    } 
    if(index == -1 || index > [appdata.categories count]){ 
    [appdata.categories addObject:category]; 
    index = [appdata.categories count]; 
    } 
    NSMutableArray* ary = [[NSMutableArray alloc] init]; 
    [ary addObject:price]; 
    [ary addObject:category]; 
    [ary addObject:date]; 
    [appdata.items addObject:ary]; 
} 

-(void)editAppDataItemId:(NSInteger)identifier itemPrice:(NSString*)price itemCategory:(NSString*)category itemDate:(NSDate*)date{ 
    NSInteger index = [appdata.categories indexOfObjectIdenticalTo:category]; 
    if(index == -1 || index > [appdata.categories count]){   
    [appdata.categories addObject:category]; 
    index = [appdata.categories count]; 
    } 
    NSMutableArray* ary = [[NSMutableArray alloc] init]; 
    [ary addObject:price]; 
    [ary addObject:category]; 
    [ary addObject:date]; 
    [appdata.items replaceObjectAtIndex:identifier withObject:ary]; 
} 

-(void)deleteAppDataItemId:(NSInteger)identifier{ 
    [appdata.items removeObjectAtIndex:identifier]; 
} 

-(void)saveData{ 
    NSData* data = [[NSMutableData alloc] init]; 
    NSKeyedArchiver* archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; 
    [archiver encodeObject:appdata forKey:DATAKEY]; 
    [archiver finishEncoding]; 
    [data writeToFile:[self dataFilePath] atomically:YES]; 
    [archiver release]; 
    [data release]; 
} 

-(NSString*)dataFilePath{ 
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString* documentsDirectory = [paths objectAtIndex:0]; 
    return [documentsDirectory stringByAppendingPathComponent:FILENAME]; 
} 

-(NSMutableArray*)categories{ 
    return appdata.categories; 
} 

-(NSString*)allAmount{ 
    NSInteger amount = 0; 
    int i; 
    for (i=0; i<[appdata.items count]; i++) { 
    NSMutableArray* item = [appdata.items objectAtIndex:i]; 
    NSString* price = [item objectAtIndex:0]; 
    NSInteger n = [price integerValue]; 
    amount += n; 
    } 
    return [NSString stringWithFormat:@"合計:: %d 円", amount]; 
} 

-(NSInteger)amountYear:(NSInteger)searchYear Month:(NSInteger)searchMonth{ 
    NSMutableArray* result = [[MyAppDataController instance] itemsYear:searchYear Month:searchMonth]; 
    NSInteger amount = 0; 
    int i; 
    for (i=0; i<[result count]; i++) { 
    NSString* str = [[[result objectAtIndex:i] objectAtIndex:1] objectAtIndex:0]; 
    NSInteger n = [str integerValue]; 
    amount += n; 
    } 
    //[result release]; 
    return amount; 
} 

-(NSMutableArray*)searchByCategoryYear:(NSInteger)searchYear Month:(NSInteger)searchMonth Category:(NSString*)searchCategory{ 
    NSMutableArray* result = [self itemsYear:searchYear Month:searchMonth]; 
    int i; 
    for (i=0; i<[result count]; i++) { 
    NSString* category = [[[result objectAtIndex:i] objectAtIndex:1] objectAtIndex:1]; 
    if (![searchCategory isEqualToString:category]) { 
     [result removeObjectAtIndex:i]; 
    } 
    } 
    return result; 
} 

-(NSMutableArray*)itemsYear:(NSInteger)searchYear Month:(NSInteger)searchMonth{ 
    NSMutableArray* result = [[NSMutableArray alloc] init]; 
    int i; 
    for (i=0; i<[appdata.items count]; i++) { 
    NSMutableArray* item = [appdata.items objectAtIndex:i]; 
    NSDate* date = [item objectAtIndex:2]; 

    NSCalendar* cal = [[NSCalendar alloc] 
         initWithCalendarIdentifier:NSGregorianCalendar]; 
    unsigned int unitFlags = NSYearCalendarUnit | 
     NSMonthCalendarUnit | 
     NSDayCalendarUnit | 
     NSHourCalendarUnit | 
     NSMinuteCalendarUnit | 
     NSSecondCalendarUnit; 
    NSDateComponents *components = [cal components:unitFlags fromDate:date]; 

    NSInteger itemYear = [components year]; 
    NSInteger itemMonth = [components month]; 

    if (itemYear == searchYear && itemMonth == searchMonth) { 
     NSMutableArray* ary = [[NSMutableArray alloc] init]; 
     [ary addObject:[NSNumber numberWithInt:i]]; 
     [ary addObject:item]; 
     [result addObject:ary]; 
    } 
    } 
    return result; 
} 

-(NSMutableArray*)getByIdentifier:(NSInteger)identifier{ 
    return [appdata.items objectAtIndex:identifier]; 
} 

@end 

.h

#define FILENAME @"archive" 
#define DATAKEY @"data" 

#import <UIKit/UIKit.h> 
#import "MyApplicationData.h" 

@interface MyAppDataController : NSObject { 
    MyApplicationData* appdata; 
} 

@property (nonatomic, retain) MyApplicationData* appdata; 

-(void)loadData; 
-(void)addAppDataItemPrice:(NSString*)price itemCategory:(NSString*)category itemDate:(NSDate*)date; 
-(void)editAppDataItemId:(NSInteger)identifier itemPrice:(NSString *)price itemCategory:(NSString *)category itemDate:(NSDate *)date; 
-(void)deleteAppDataItemId:(NSInteger)identifier; 
-(void)saveData; 
-(NSMutableArray*)categories; 
-(NSString*)dataFilePath; 
-(NSString*)allAmount; 
-(NSString*)amountYear:(NSInteger)searchYear Month:(NSInteger)searchMonth; 
-(NSMutableArray*)itemsYear:(NSInteger)searchYear Month:(NSInteger)searchMonth; 
-(NSMutableArray*)searchByCategoryYear:(NSInteger)searchYear Month:(NSInteger)searchMonth Category:(NSString *)searchCategory; 
-(NSMutableArray*)getByIdentifier:(NSInteger)identifier; 

+(id)instance; 

@end 
+3

Quel est votre code actuel? –

+0

J'ai ajouté le code réel. – marcy

Répondre

12

La mise en œuvre de votre

-(NSString*)amountYear:(NSInteger)searchYear Month:(NSInteger)searchMonth; 
méthode

(qui est défini dans votre .h) est mis en œuvre avec un NSInteger:

-(NSInteger)amountYear:(NSInteger)searchYear Month:(NSInteger)searchMonth 

Je peux seulement supposer que le .h est faux et qu'il devrait y avoir un NSInteger et non une NSString *

0

Je fais l'habitude de copier les définitions des méthodes passées de l'en-tête à la mise en œuvre (et vice versa) spécifiquement pour éviter ce genre d'erreur. Ce que je fais. Beaucoup.

J'ai finalement écrit un script utilisateur Xcode pour générer le cadre de mise en œuvre pour moi. C'est rapide et sale mais ça me fait gagner beaucoup de temps. Ici c'est si vous pensez que cela pourrait être utile.

#! /usr/bin/env ruby -w 


dash="------------------------------------" 
r=/(^.+);/ # find entire function definition 
pr=/(\w+(:|;))/ #find named parameters to make selector style string 
s=STDIN.read 
s.each_line() do |l| 
    m=l.match(r) 
    if m 
    n=l.match(/:/) 
    if n #if the function as one or more parameters 
    params=l.scan(/(\w+:)/) 
    puts m.captures[0] + "{\n\n}//"+dash + params.to_s + dash +"\n\n" 
    else #method has no parameters 
     puts m.captures[0]+ "{\n\n}//"+dash + m.captures[0] + dash +"\n\n" 
    end 
    end 
end 
Questions connexes