gpt4 book ai didi

objective-c - 我怎样才能摆脱这种冲突类型的警告?

转载 作者:行者123 更新时间:2023-12-03 17:28:01 25 4
gpt4 key购买 nike

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

最佳答案

实现您的

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

方法(在 .h 中定义)是使用 NSInteger 实现的:

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

我只能假设 .h 是错误的,它应该是 NSInteger 而不是 NSString*

关于objective-c - 我怎样才能摆脱这种冲突类型的警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1708783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com