user1078065
user1078065

Reputation: 412

ios converting project to arc

Let's assume that i have a method that looks like this.

-(void)doSmth {
    NSString *one = [[NSString alloc] initWithFormat:@"%@",someNumber];

    NSString *two = [[NSString alloc] initWithFormat:@"%@",someOtherNumer];

    [one release];
}

Project was created without ARC. I would like to convert it to ARC.

My question is: will there be leaks after converting to arc?

Thanks

Upvotes: 1

Views: 280

Answers (3)

user3540599
user3540599

Reputation: 721

enter image description here

if we need to convert to complete project to ARC then Edit ->convert -> to Objective-C ARC

or if u need to convert a particular file then projectNav ->build Phases ->compile source in that particular .m file add -fno-objc-arc

enter image description here

Upvotes: 0

BJ Homer
BJ Homer

Reputation: 49054

No. The ARC converter will remove the explicit call to release, and the compiler will automatically insert release calls for both one and two at compile time.

End result: no leaks here.

Upvotes: 1

Simon Goldeen
Simon Goldeen

Reputation: 9080

You will have to remove [one release]; as in ARC this generates an error.

With regards to your question, after switching to ARC (and removing the release statement) it will not leak.

Edit: It would probably be better to write the code like this:

NSString *one = [[NSString alloc] initWithFormat@"one"];

or like this:

NSString *one = @"one";

Upvotes: 0

Related Questions