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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:55:43+00:00 2026-06-03T07:55:43+00:00

i am currently decoding my data send over the air using initWithDecoder. One of

  • 0

i am currently decoding my data send over the air using initWithDecoder. One of the things i have noticed is when it is called it can not see the variables within scope and therefore does not behave the way i intend it to, here is an example of what i have done:

first i encode all the data:

-(void) encodeWithCoder: (NSCoder *) encoder 
{
  for(BaseGroup *attackCard in myArray)
  {
    [encoder encodeObject: attackCard];
  }
}

within the same class i keep a note of the number of items i have:

self.numItems = [self.myArray count]; 

and within initWithCoder i expect to iterate and decode the encoded NSData as follows

-(id) initWithCoder: (NSCoder *) decoder
{

  for(int i =0; i < self.numItems; i++)
  {
    [self.myArray addObject:[decoder decodeObject]];   
  }

  return self;

}

trouble is that initWithCoder is out of scope from the variable numItems and therefore does not iterate at all. Is there a way around this?

  • 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-03T07:55:44+00:00Added an answer on June 3, 2026 at 7:55 am

    Why don’t you encode/decode the full array? This would make things easier…

    Also, don’t forget to call [super init...]!

    -(void) encodeWithCoder: (NSCoder *) encoder 
    {
          [encoder encodeObject: myArray];
    }
    
    
    -(id) initWithCoder: (NSCoder *) decoder
    {
       if ((self = [super init]))
           self.myArray = [decoder decodeObject];
       return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently in the process of deciding whether or not to use Core Data
Currently I have a class that looks like this: public class MyClass : IMyClass
Currently developing an application using the newest version of symfony, obtained through PEAR. This
Currently I have a DetailsView attached to a GridView. When you select an item
Currently, I have something like: public partial class Form1 : Form { delegate void
Currently I'm working with ASP.NET 2.0, which may explain why I'm not as up
Sometimes procedural programming is absolutely unavoidable when processing data. I am currently working on
Currently I'm working on Inventory Management application (later on this can be integrated with
I have a non document-based Core Data application. There's an NSTreeController that manages a
I have 160 bits of random data. Just for fun, I want to generate

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.