Graham Bell
Graham Bell

Reputation: 1149

Objective C ARC equivalent for self?

What is the equivalent keyword i can use in the place of self in ARC enabled projects? ex:- [self mymethod]; what is ARC equivalent of this method call?

Upvotes: 0

Views: 153

Answers (3)

oldtimer
oldtimer

Reputation: 51

I don't quite get it? Why ARC should have different syntax for method calls? It is an automatic memory management, where in most cases you won't need to use retain/release, nothing more. So it would look like this:

[self mymethod];

Upvotes: 5

self
self

Reputation: 1215

In ARC(Automatic Reference Counting),you don't need to release or retain. It has nothing to do with calling methods!

ARC - Automatic Reference Counting implements automatic memory management for Objective-C objects and blocks, freeing the programmer from the need explicitly insert retains and releases. Since this is handled at compile time, no collector process is need to continually clear memory and remove unreferenced objects.

For calling a method, you still do it this way:[self mymethod];

Upvotes: 1

ewiinnnnn
ewiinnnnn

Reputation: 995

it's still the same

[self myMethod];

But in ARC environment, IIRC, you need to do it like this: (I don't know if this is the source of your question, but when I migrated the first time to ARC, I get compile error if I'm not doing this).

@interface myController()
- (void)myMethod; // you need to declare the method here, if you haven't declared it on the .h
@end

@implementation

- (void)viewDidLoad
{
  [super viewDidLoad];
  [self myMethod];
}

- (void)myMethod
{
  NSLog(@"!");
}

@end

hope this help

Upvotes: 0

Related Questions