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 4015946
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:40:50+00:00 2026-05-20T09:40:50+00:00

I am working on making an existing iPhone/iPad project backwards compatible down to iPhoneOS

  • 0

I am working on making an existing iPhone/iPad project backwards compatible down to iPhoneOS 3.0.

My current test device is an iPod Touch with 3.1.3 on it.

The following bit of code is causing problems:

Class gestureRecognizer = NSClassFromString(@"UISwipeGestureRecognizer");

if (gestureRecognizer != nil)
{

    UISwipeGestureRecognizer * leftSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self 
                                                                                               action:@selector(didSwipeLeft:)];
    leftSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    leftSwipeRecognizer.delegate = self;
    [self.view addGestureRecognizer:leftSwipeRecognizer];
    _leftSwipeRecognizer = leftSwipeRecognizer;
}

According to Apple documentation UIGestureRecognizer is defined starting from iOS 3.2. So I expect Class gestureReconizer to be nil on previous OS version and that the following if to be skipped. However it does not skip. gestureRecognizer is not nil, the code inside the if starts executing and crashes at leftSwipeRecognizer.direction because:

-[UISwipeGestureRecognizer setDirection:]: unrecognized selector sent to instance 0x1e5720

This situation is quite confusing. I guess I am doing everything by the book. I try to check if a class exists before I use it, however the class which shouldn’t be there, is there, fools my test, does not comply with its expected specs, and crashes.

I could, of course put a few respondsToSelector checks here and there to work around this crash, but it wouldn’t be an elegant way to do it.

Any other suggestions?

  • 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-05-20T09:40:50+00:00Added an answer on May 20, 2026 at 9:40 am

    According to the UIGestureRecognizer class reference, under “Usage Special Considerations”, you actually do need to do an additional respondsToSelector check after checking if the class exists.

    This is directly from the documentation:

    To determine whether a class is
    available at runtime in a given iOS
    release, you typically check whether
    the class is nil. Unfortunately, this
    test is not cleanly accurate for
    UIGestureRecognizer. Although this
    class was publicly available starting
    with iOS 3.2, it was in development a
    short period prior to that. Although
    the class exists in an earlier
    release, use of it and other
    gesture-recognizer classes are not
    supported in that earlier release. You
    should not attempt to use instances of
    those classes.

    To determine at runtime whether you
    can use gesture recognizers in your
    application, test whether the class
    exists and, if it does, allocate an
    instance and see check if it responds
    to the selector locationInView:. This
    method was not added to the class
    until iOS 3.2. The code might look
    like the following:

    UIGestureRecognizer *gestureRecognizer = [[UIGestureRecognizer alloc] 
        initWithTarget:self action:@selector(myAction:)];
    
    if (![gestureRecognizer respondsToSelector:@selector(locationInView:)]) {
        [gestureRecognizer release];
        gestureRecognizer = nil;
    }
    // do something else if gestureRecognizer is nil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At my current job I've been working on making web apps with Java, Tapestry,
I've started working on an existing, large ASP.NET project and I'd love to get
I'm working on an existing Java EE project with various maven modules that are
I've recently started working in ASP.NET and RDBMS.I'm making a test form where I
I have been working on making my website mobile compatible. Whilst I have successfully
I'm currently working on a project using the current if statement and i'm sure
I'm working on a personal project involving map-making tools for a tabletop game that
I am currently working on an OPENGL ES 2.0 project. I am making a
I'm working on making a simple server application with python, and I'm trying to
Hi im making a custom Textbox i got everty thing working but how do

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.