I am following "Programming in Objective-C" 3rd edition and I am having problems with the first example.
I keep getting this error:
Semantic Issue: 'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode
Here is my code:
// // main.m // prog1 // // Created by Steve Kochan on 1/30/11. // Copyright 2011 ClassroomM, Inc.. All rights reserved. // #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog (@"Programming is fun!"); [pool drain]; return 0; }
Any insight will be greatly appreciated.
An object that supports Cocoa's reference-counted memory management system.
Auto-release pools are created by the Cocoa runtime and live on the current execution stack. When object references are autoreleased (instead of fully released), rather than decrementing the object's reference count, the object is placed in the currently active auto-release pool.
Memory management in swift is handled with ARC (= automatic reference counting). This means that active references to objects are counted and objects are released when they aren't referenced anymore.
The compiler is being asked to compile the file with ARC (automatic reference counting) enabled. Turn that off or, better yet, modernize your example:
int main (int argc, const char * argv[]) { @autoreleasepool { NSLog (@"Programming is fun!"); } return 0; }
(No, I can't tell you how, specifically, to turn off ARC, if that was the route you were to go down due to the aforementioned NDA.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With