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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:30:48+00:00 2026-06-14T22:30:48+00:00

I’m following the Your Second iOS App and I decided to play with the

  • 0

I’m following the “Your Second iOS App” and I decided to play with the code to understand Objective C well…

What I’m trying to do is simply adding an object to a mutable array in a class. Here are the classes:

BirdSighting.h

#import <Foundation/Foundation.h>

@interface BirdSighting : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *location;
@property (nonatomic, copy) NSDate *date;

-(id) initWithName: (NSString *) name location:(NSString *) location date:(NSDate *) date;
@end

BirdSighting.m

#import "BirdSighting.h"

@implementation BirdSighting
-(id) initWithName:(NSString *)name location:(NSString *)location date:(NSDate *)date
{
    self = [super init];

    if(self) {
        _name = name;
        _location = location;
        _date = date;

        return self;
    }

    return nil;
}

@end

BirdSightingDataController.h

#import <Foundation/Foundation.h>
@class BirdSighting;

@interface BirdSightingDataController : NSObject
@property (nonatomic, copy) NSMutableArray *masterBirdSightingList;

- (NSUInteger) countOfList;
- (BirdSighting *) objectInListAtIndex: (NSUInteger) theIndex;
- (void) addBirdSightingWithSighting: (BirdSighting *) sighting;
@end

BirdSightingDataController.m

#import "BirdSightingDataController.h"

@implementation BirdSightingDataController
- (id) init {
    if(self = [super init]) {
        NSMutableArray *sightingList = [[NSMutableArray alloc] init];
        self.masterBirdSightingList = sightingList;
        return self;
    }

    return nil;
}

-(NSUInteger) countOfList 
{
    return [self.masterBirdSightingList count];
}

- (BirdSighting *) objectInListAtIndex: (NSUInteger) theIndex
{
    return [self.masterBirdSightingList objectAtIndex:theIndex];
}

- (void) addBirdSightingWithSighting: (BirdSighting *) sighting
{
    [self.masterBirdSightingList addObject:sighting];
}
@end

And this is where I’m trying to add a BirdSighting instance to the mutable array:

#import "BirdsMasterViewController.h"
#import "BirdsDetailViewController.h"

#import "BirdSightingDataController.h"
#import "BirdSighting.h"

@implementation BirdsMasterViewController

- (void)awakeFromNib
{
    [super awakeFromNib];

    BirdSightingDataController *dataController = [[BirdSightingDataController alloc] init];

    NSDate *date = [NSDate date];
    BirdSighting *sighting = [[[BirdSighting alloc] init] initWithName:@"Ebabil" location:@"Ankara" date: date];

    [dataController addBirdSightingWithSighting: sighting];
    NSLog(@"dataController: %@", dataController.masterBirdSightingList);

    self.dataController = dataController;

}
..........
@end

It throws NSInvalidArgumentException in BirdSightingDataController addBirdSightingWithSighting method…

What am I doing wrong?

This is the full debug output:
2012-11-26 01:22:38.495 BirdWatching[4597:c07] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x71899d0
2012-11-26 01:22:38.496 BirdWatching[4597:c07] * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x71899d0’

  • 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-14T22:30:49+00:00Added an answer on June 14, 2026 at 10:30 pm

    This line:

    BirdSighting *sighting = [[[BirdSighting alloc] init] initWithName:@"Ebabil" location:@"Ankara" date: date];
    

    should be:

    BirdSighting *sighting = [[BirdSighting alloc] initWithName:@"Ebabil" location:@"Ankara" date: date];
    

    You can’t call two initializers.

    Update:

    Based on the complete error message I now see the problem. The NSMutableArray you think you have for the property is really an NSArray. This is caused by defining the property with copy.

    When you define copy for a property, it makes an immutable copy of the object. So when you assign your NSMutableArray, an immutable copy is made and then assigned to the instance variable. So you end up assigning an NSArray, not an NSMutableArray.

    A fix is to change the property definition from:

    @property (nonatomic, copy) NSMutableArray *masterBirdSightingList;
    

    to:

    @property (nonatomic, strong) NSMutableArray *masterBirdSightingList;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

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.