0

I'm totally new to the IOS app creation game, so be gentle. I'm getting the expected expression error down at the autorelease section. If someone could help me out here, that'd be great.

// Load images
NSArray *imageNames = @[@"fold1.png", @"fold2.png", @"fold3.png", @"fold4.png",
                        @"fold5.png", @"fold6.png", @"fold7.png", @"fold8.png",
                        @"fold9.png", @"fold10.png", @"fold11.png", @"fold12.png",
                        @"foldclear.png"];

NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
    [images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}

// Normal Animation
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 108, 324, 460)];
animationImageView.animationImages = images;
animationImageView.animationDuration = 0.5;
animationImageView.animationRepeatCount = 5;

[self.view addSubview:animationImageView];
[animationImageView startAnimating];
// Add swipeGestures
UISwipeGestureRecognizer *oneFingerSwipeLeft = [[[UISwipeGestureRecognizer alloc]
                                                 initWithTarget:self
                                                 action:@selector(oneFingerSwipeLeft:) autorelease:];
[oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:oneFingerSwipeLeft];

UISwipeGestureRecognizer *oneFingerSwipeRight = [[[UISwipeGestureRecognizer alloc]
                                                  initWithTarget:self
                                                  action:@selector(oneFingerSwipeRight:) autorelease:];
[oneFingerSwipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[[self view] addGestureRecognizer:oneFingerSwipeRight];

}

1
  • The syntax is incorrect: the colon doesn't have any purpose there and autorelease call is out of place as you are missing closing square brackets. Bu in general, whenever you encounter any kind of error and need assistance at solving it, please provide the full error text as well as a description of how you reproduce it (in this case - during the build). Commented Jan 19, 2015 at 18:17

1 Answer 1

1

For ARC (automatic reference count) projects, you should not be using autorelease at all. The system will determine when to release objects for you. However, you don't have to use ARC.


The autorelease method does not take any parameters. It is called simply:

[object autorelease];

A colon indicates an expected parameter.

[object initWithTarget:self action:@selector(oneFingerSwipeLeft:)];

Here, you have passed self as the first parameter and @selector(oneFingerSwipeLieft:) as the second parameter. You have indicated that oneFingerSwipeLeft: will require one parameter to be passed to it with your usage of : within the @selector().


Edit: In addition, it appears that you have not properly counted the number of methods that are being called on that line. You should be able to pull out each [] individually as a method. I will take the first line and break it apart for you so you can see:

UISwipeGestureRecognizer *oneFingerSwipeLeft = [[[UISwipeGestureRecognizer alloc]
                                               initWithTarget:self
                                               action:@selector(oneFingerSwipeLeft:) autorelease:];

becomes:

UISwipeGestureRecognizer *oneFingerSwipeLeft = [UISwipeGestureRecognizer alloc];
oneFingerSwipeLeft = [oneFingerSwipeLeft initWithTarget:self
                                                 action:@selector(oneFingerSwipeLeft:)
                                            autorelease];

However, this would indicate that there is a method with signature initWithTarget:action:autorelease on UISwipeGestureRecognizer. There isn't one, nor would it be valid Objective-C to create one.

Instead, you should be using initWithTarget:action: as one selector and autorelease as its own as such:

UISwipeGestureRecognizer *oneFingerSwipeLeft = [UISwipeGestureRecognizer alloc];
oneFingerSwipeLeft = [oneFingerSwipeLeft initWithTarget:self
                                                 action:@selector(oneFingerSwipeLeft:)];
oneFingerSwipeLeft = [oneFingerSwipeLeft autorelease];

Putting this together in one line looks like:

UISwipeGestureRecognizer *oneFingerSwipeLeft = [[[UISwipeGestureRecognizer alloc]
                                               initWithTarget:self
                                               action:@selector(oneFingerSwipeLeft:)] autorelease];

Essentially, you were missing a ].

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much for the answer, but now I'm getting an Expected Identifier error on the last semicolon
I'm not sure what you mean by that.
You have mismatched [ and ]. You open three, but only close two in your screenshot.
Ah, alright. Thank you so much for all your help. I think I'm finally starting to catch on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.