Как я могу избавиться от этого предупреждения типа конфликта? - PullRequest
0 голосов
/ 10 ноября 2009

Objective-C

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

Как мне избавиться от этого предупреждения?

.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

Ответы [ 2 ]

12 голосов
/ 10 ноября 2009

Реализация вашего

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

метод (который определен в вашем .h) реализован с помощью NSInteger:

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

Я могу только предположить, что .h неверен и что он должен быть NSInteger, а не NSString *

0 голосов
/ 10 ноября 2009

Я использую привычку копировать и вставлять определения методов из заголовка в реализацию (и наоборот) специально для предотвращения такого рода ошибок. Который я делаю. Много.

В конце концов я просто написал пользовательский скрипт Xcode, чтобы сгенерировать для меня фрейм реализации. Это быстро и грязно, но это экономит мне много времени. Вот если вы думаете, что это может быть полезно.

#! /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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...