Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8827653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:25:23+00:00 2026-06-14T07:25:23+00:00

While working on a project i made a class i instantiate in another class

  • 0

While working on a project i made a class i instantiate in another class (nothing special) but if i try to call a method for this instance i get this:

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[CALayer animate]: unrecognized selector sent to instance

here is the class .h :

#import <QuartzCore/QuartzCore.h>

@interface SFStripe : CALayer {

        NSTimer *animation;

}

- (id)initWithXPosition:(NSInteger)positionX yPosition:(NSInteger)positionY;
- (id)initEndedWithXPosition:(NSInteger)positionX yPosition:(NSInteger)positionY;
- (void)animate;
- (void)reduceSize;
- (void)logSomething;

@property NSTimer *animation;


@end

and here the .m :

#import "SFStripe.h"

@implementation SFStripe

@synthesize animation;

- (id)initWithXPosition:(NSInteger)positionX yPosition:(NSInteger)positionY {

    self = [CALayer layer];
    self.backgroundColor = [UIColor blackColor].CGColor;
    self.frame = CGRectMake(positionX, positionY, 5, 20);
    self.cornerRadius = 5;

    return self;
}

- (id)initEndedWithXPosition:(NSInteger)positionX yPosition:(NSInteger)positionY {

    self = [CALayer layer];
    self.backgroundColor = [UIColor grayColor].CGColor;
    self.frame = CGRectMake(positionX, (positionY + 7.5), 5, 5);
    self.cornerRadius = 2;
    self.delegate = self;
    return self;
}

- (void) logSomething {
    NSLog(@"It did work!");
}

- (void)reduceSize {

    if (self.frame.size.width > 0 && self.frame.size.height >= 5) {
        self.frame = CGRectMake(self.frame.origin.x, (self.frame.origin.y - 0.5), self.frame.size.width, (self.frame.size.height - 0.5));
        [self setNeedsDisplay];
        NSLog(@"Width: %d", (int)self.frame.size.width);
        NSLog(@"Height: %d", (int)self.frame.size.height);
    } else {
        self.backgroundColor = [UIColor grayColor].CGColor;
        self.frame = CGRectMake(self.frame.origin.x, (self.frame.origin.y + 7.5), 5, 5);
        [animation invalidate];
    }

}

- (void)animate {

    animation = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(reduceSize) userInfo:nil repeats:YES];
}


@end

i imported this class into a fresh project just to see if it is working there but get the same error. here is how i call one of the methods for an instance of the class (i get the same error for all of the methods)

in the mainview.h (of the clean project):

#import <UIKit/UIKit.h>
#import "SFStripe.h"
#import <QuartzCore/QuartzCore.h>

@interface STViewController : UIViewController {
    SFStripe *stripe;
}
- (IBAction)animate:(id)sender;

@end

i created the instance and in the .m i let the action call the method for the instance:

#import <QuartzCore/QuartzCore.h>
#import "STViewController.h"
#import "SFStripe.h"

@interface STViewController ()

@end

@implementation STViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    stripe = [[SFStripe alloc] initWithXPosition:30 yPosition:30];
    [self.view.layer addSublayer:stripe];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.


}

- (IBAction)animate:(id)sender {

    [stripe animate];

}
@end

sorry for all the code but i cant find an answer for this problem that helps and hope someone can help me!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:25:24+00:00Added an answer on June 14, 2026 at 7:25 am

    This is not the correct way to write an initializer:

    - (id)initWithXPosition:(NSInteger)positionX yPosition:(NSInteger)positionY 
    {
        self = [CALayer layer];
        ...
    

    You’re assigning self to be a plain old CALayer instance, rather than an instance of your subclass.

    Use self = [super init] instead, and then check that self is not nil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While working on my final project for my AS/400 Course, I encountered this problem
recently, while working on a db2 -> oracle migration project, we came across this
So I have been working on this project for a short while now. I
While I was working on an University project, I used a project-internal profiler made
While working a project tonight, I ended up using one .js resource file for
While working on an Xcode project i keep getting the spinning wheel while switching
while working on a school project i ran into a problem using javascript to
While working on an AppEngine connected Android project, I occasionally have problems with RequestFactory
While writing a login system for a web project Im working on I came
I'm working on the UI side of a WPF project. My favourite reference while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.