Pergunta

I have a problem with my 64-Bit IOS Simulation..

odendi is a BOOL value in my CoreDate.

This is the my entity class file.

    #import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class Fatura, Kart;

@interface Odeme : NSManagedObject

@property (nonatomic, retain) NSNumber *odendi;

I have a button. When user tap this button this code should run ;

 if (odeme.odendi == [NSNumber numberWithInt:1]) {

        odeme.odendi = [NSNumber numberWithBool:NO];
    }

    else
    {
    odeme.odendi = [NSNumber numberWithBool:YES];

    }

NSLog(@"%@",odeme.odendi);

It's working with 32-Bit IOS Simulation perfectly. But doesn't work in 64 Bit.When i click this button 4 times.It should NSLog 0 1 0 1 I tried to send

odeme.odendi = [NSNumber numberWithLong:1];

it doesn't work.

This is the 64-Bit IOS 7.0 Iphone Simulator NSLog ;

2014-05-04 15:15:06.971 ProjectName[5314:60b] 1

2014-05-04 15:15:07.868 ProjectName[5314:60b] 1

2014-05-04 15:15:08.662 ProjectName[5314:60b] 1

2014-05-04 15:15:08.662 ProjectName[5314:60b] 1

This is the 32-Bit IOS 7.0 Iphone Simulation NSLog ;

2014-05-04 15:22:01.878 ProjectName[5368:60b] 1

2014-05-04 15:22:02.770 ProjectName[5368:60b] 0

2014-05-04 15:22:04.523 ProjectName[5368:60b] 1

2014-05-04 15:22:05.399 ProjectName[5368:60b] 0

Can someone tell me what should I do ?

Thanks everyone...

Foi útil?

Solução

My first thought, if odendi is supposed to represent a BOOL, then why not use it as one?

if ([odeme.odendi boolValue]) {
    odeme.odendi = @NO;
} else {
    odeme.odendi = @YES;
}

Or even eliminate the if-else structure.

odeme.odendi = [NSNumber numberWithBool:![odeme.odendi boolValue]];

Or as Martin suggests some different syntax for the same statement:

odeme.odendi = @(![odeme.odendi boolValue]);

Don't miss that exclamation point.


Given that this seems to work on 32-bit and not on 64-bit, I suspect this might be the problem:

if (odeme.odendi == [NSNumber numberWithInt:1])

Which is why you should have put a log in each branch instead of just below it all. It would let you know that your if is evaluating incorrectly and the problem is here, rather than inside either branch.

You could try [NSNumber numberWithInteger:1], which is different between 32-bit and 64-bit. I have no idea if this will actually work or not. At the end of the day though, you say odeme.odendi is a BOOL. It should be used as such. Don't compare it to a number. Don't even compare it to an [NSNumber numberWithBOOL:YES] or @YES. Just grab the BOOL value. It will evaluate to YES or NO and the correct branch should be chosen.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top