38

I'm trying to make a simple animation image in iPhone from an image array:

- (void)viewDidLoad {
    NSArray *imageArray;
    imageArray = [[NSArray alloc] initWithObjects:
                  [UIImage imageNamed:@"sun1"],
                  [UIImage imageNamed:@"sun2"],
                  nil];
    fadeImage.animationImages = imageArray;
    fadeImage.animationDuration = 1;
    [imageArray release];  //==== HERE IS WHERE I GET THE ERROR ======

How can I fix this?

Jean
  • 7,623
  • 6
  • 43
  • 58
Victor Barba
  • 401
  • 1
  • 4
  • 3
  • 1
    You can disable ARC as your choice Go [this link][1], and try that. [1]: http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project?answertab=active#tab-top – Wanbok Choi Apr 05 '13 at 21:49
  • Xcode has the tool "Edit:Refactor:Convert to Objective-C ARC". –  Apr 05 '13 at 22:38

1 Answers1

80

Solution #1:

Just remove the release statement. ARC will manage it for you.

[imageArray release]; // remove this line

ARC is Auto Reference Counting. As opposite to manual reference counting.
There are a few great videos of talks from WWDC. I can provide the link if you wish to watch them.

In Transitioning to ARC Release Notes, see ARC Enforces New Rules:

You cannot explicitly invoke dealloc, or implement or invoke retain, release, retainCount, or autorelease.

The prohibition extends to using @selector(retain), @selector(release), and so on.

Solution #2:

If you do not wish to convert the code to ARC (e.g. you are not writing a new application, but are maintaining an old one / or you imported so much code that moving to ARC is not worth it) you can disable ARC.

  • Disabling ARC for selected files To disable ARC, you can use the -fno-objc-arc compiler flag for specific files. Select the target and go to Build Phases -> Compile Sources. Edit the Compiler Flags and add -fno-objc-arc

  • Disabling ARC for the project
    Source:How to disable Xcode4.2 Automatic Reference Counting

    • Click on you project, in the left hand organizer.
    • Select your target, in the next column over.
    • Select the Build Settings tab at the top.
    • Scroll down to "Objective-C Automatic Reference Counting" (it may be listed as
    • "CLANG_ENABLE_OBJC_ARC" under the User-Defined settings group), and set it to NO.
Hardik Thakkar
  • 15,269
  • 2
  • 94
  • 81
Jean
  • 7,623
  • 6
  • 43
  • 58
  • 2
    You should probably elaborate on solution #2, though. Specifically, the `-fno-objc-arc` flag is your friend. – Richard J. Ross III Apr 05 '13 at 21:54
  • I removed the line... – Victor Barba Apr 06 '13 at 02:02
  • Sorry I press return... I removed the line and I got this return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); and the error Thread 1: signal SIGABRT I'm just trying to make a simple animation, thank you for taking the time to answer this question wherever you are – Victor Barba Apr 06 '13 at 02:05
  • Still no luck with the animation problem, any body knows how to make a simple animation on Xcode? – Victor Barba Apr 06 '13 at 17:51
  • @VictorBarba `SIGABRT` means a serious, unrecoverable, error occurred and `abort()` was called. Where did you get the code? Is it compatible with your app's memory management? Are you linking to a 3rd party developer framework? Have you tried disabling ARC entirely? Since we are drifting out of the topic of this question (*why `[anObject release];` produces an error under ARC*), maybe you could open a new question about getting the `SIGABRT` signal, in which you would provide more details, including a short, self contained, compilable, example. This way we could help better. – Jean Apr 06 '13 at 18:47
  • Solution two worked for me to get NSLogger working. Thanks! – Corona Feb 01 '17 at 17:17