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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:45:13+00:00 2026-06-17T06:45:13+00:00

Primarily, I’m attempting to archive an NSDictionary with a UITouch in it. I keep

  • 0

Primarily, I’m attempting to archive an NSDictionary with a UITouch in it. I keep receiving an error that says ‘-[UITouch encodeWithCoder:]: unrecognized selector sent to instance’.

If I remove the UITouch object from the dictionary, i don’t receive the error.

I’ve been trying to figure it out myself, including searching through google for the past few hours, and have yet to find how to store a UITouch object in an NSDictionary.

here’s the method I’m using:

- (void)sendMoveWithTouch:(id)touch andTouchesType:(TouchesType)touchesType {
     MessageMove message;
     message.message.messageType = kMessageTypeMove;
     message.touchesType = touchesType;
     NSData *messageData = [NSData dataWithBytes:&message length:sizeof(MessageMove)];

     NSMutableData *data = [[NSMutableData alloc] init];
     NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];

     [archiver encodeObject:@{@"message" : messageData, @"touch": touch} forKey:@"touchesDict"]; //RECEIVE ERROR HERE. If I remove the UITouch object, everything passes correctly

     [archiver finishEncoding];

     [self sendData:data];
}

Any help would be greatly appreciated.

  • 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-17T06:45:15+00:00Added an answer on June 17, 2026 at 6:45 am

    UITouch doesn’t, by itself, conform to the <NSCoding> protocol, since it doesn’t have a trivial/obvious serialized representation (like a string or an array, which are basic data types). What you have to do is make it conform to this protocol by extending its class and deciding which properties should it serialize and in what kind of format. For example:

    @implementation UITouch (Serializable)
    
    - (void)encodeWithCoder:(NSCoder *)coder
    {
        [coder encodeObject:@([self locationInView:self.view].x) forKey:@"locationX"];
        [coder encodeObject:@([self locationInView:self.view].y) forKey:@"locationY"];
    }
    
    - (id)initWithCoder:(NSCoder *)decoder
    {
        if (self = [super init]) {
            // actually, I couldn't come up with anything useful here
            // UITouch doesn't have any properties that could be set
            // to a default value in a meaningful way
            // there's a reason UITouch doesn't conform to NSCoding...
            // probably you should redesign your code!
        }
        return self;
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I code primarily in javascript and in vb.net. I've found that if I can
Primarily I'm looking for a way to create an nstimer scheduledTimerWithTimeInterval that repeats every
A primarily technical question- I am developing an interface that - put basically -
Using primarily the macro recorder, I created a VBA macro that sets up a
I understand that versioning in Mongoose is primarily intended to avoid issues with sub-document
My application is primarily a client for a server that really doesn't have a
I'm currently building a program that primarily uses ABSDatabase, however I am trying to
I have a Java project that I've been developing primarily in windows. I have
I'm writing a generic filter class that will be primarily used to filter persons
I now primarily write in python, however I am looking for a language that

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.