2

In versions of Xcode previous to 5, we can disable ARC in the project settings when we create the project. Now ARC is causing this problem for me.

With an property list file, for the reading step, the compiler gives me an error: "implicit conversion of 'int' to 'id' is disallowed with ARC". I did not have this problem with the same code with Xcode 4. In my property list file, The keys are numbers and also in my viewController.m When I disallow ARC for the target, the warning persists.

I don't see how I can add a compiler flag. The code (with French strings):

NSString *error;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];


NSString *plistPath = [rootPath stringByAppendingPathComponent:@"Save.plist"];

NSArray *keys = [NSArray arrayWithObjects:@"valeurCompteur1", @"valeurCompteur2", @"valeurCompteur3", @"valeurCompteur4", @"valeurCompteur5", @"nomCompteur1", @"nomCompteur2", @"nomCompteur3", @"nomCompteur4", @"nomCompteur5", nil];

NSArray *objs = [NSArray arrayWithObjects: compteur1, compteur2, compteur3, compteur4, compteur5, nameC1, nameC2, nameC3, nameC4, nameC5, nil];
jscs
  • 63,694
  • 13
  • 151
  • 195
user2187565
  • 37
  • 1
  • 5
  • Please share the code. We might be able to suggest a better option than turning off ARC. – JeremyP Oct 28 '13 at 15:17
  • Which line is giving the error? – JeremyP Oct 28 '13 at 15:22
  • The line where is the problem start by "NSArray *objs" – user2187565 Oct 28 '13 at 15:28
  • 2
    better fix your code instead of disabling ARC. – HaneTV Oct 28 '13 at 15:53
  • Refer this link [Link 1][1] Refer this link [Link 2][2] [1]: http://stackoverflow.com/questions/18883726/how-to-disable-arc-for-a-single-file-in-xcode-5 [2]: http://stackoverflow.com/questions/9018366/how-to-enable-disable-arc-in-an-xcode-project – Siva Oct 28 '13 at 17:24
  • 1
    That error means you're doing something wrong anyways, unrelated to ARC. The fact that it's an error instead of a warning is probably good overall, because it means you're forced to fix a bug. – jscs Oct 28 '13 at 19:57
  • It's strange that this issue was not present in Xcode 4 but appears under Xcode 5. Depending on your code, this could either be related to a deprecated feature or a bug in Xcode. – MacNick Oct 28 '13 at 15:18

2 Answers2

7

If you want manual reference counting (using retains and releases) you can disable ARC in the build settings.

Select the project in the project navigator. The editor area should show you a view with four tabs: info, build settings, build phases, build rules. Select build settings.

To the left of those four titles, there should be a drop down list for selecting the target you want. Select the target you don't want ARC for.

Scroll down to find the section titled "Apple LLVM 5.0 - Language - Objective-C". Under there are three settings. The bottom one should be "Objective-C Automatic Reference Counting". Set that to "No" and you will have manual reference counting.

It might be a better option, however, to fix the reported problem. It's better to use ARC than not.

To Fix the error

You say your error occurred on the line where you create the obis array. This means that one or more of the following variables is an int instead of an object:

compteur1, compteur2, compteur3, compteur4, compteur5, nameC1, nameC2, nameC3, nameC4, nameC5

If you want to put an integer into an array, you have to box it as an NSNumber e.g.

NSArray* anArray = [NSArray arrayWithObjects: [NSNumber numberWithInt: 2], nil];

There is a shorthand form of writing that now, which looks like this:

NSArray* anArray =  @[ @(2) ];
Daniel
  • 37
  • 9
JeremyP
  • 84,577
  • 15
  • 123
  • 161
2

Here are the steps I recommend:

  1. select your project or plist
  2. go to build setting
  3. select levels
  4. scroll down to Object-C Automatic Reference Counting as shown in screen shot
  5. select No from drop down against it
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Saurabh
  • 559
  • 6
  • 10