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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:20:15+00:00 2026-05-28T14:20:15+00:00

First off good day and thanks for taking the time to answer my question.

  • 0

First off good day and thanks for taking the time to answer my question.

Some background:
I have done the same thing in a regular OS X program in that I run everything in main.m

What I’m doing:

making a VERY crude app that adds a FirstName and LastName text field. The user enters some text and when they press add to address book the program gets the string info and adds it to a NSMutableArray

like i said VERY crude but for learning purposes.

What’s wrong:

AddressBook.h and AddressBook.m files

AddressBook.h

#import <Foundation/Foundation.h>

@interface AddressBook : UIViewController
{
    NSMutableArray *nameArray;

}

@property (nonatomic, copy) NSMutableArray *nameArray;


@end

AddressBook.m

#import "AddressBook.h"

@implementation AddressBook
@synthesize nameArray;
@end

side notes and comments

So I get that I create a class called AddressBook and it has a NSMutableArray

I know that if I wanted to create a new object that is part of AddressBook class I would call it in main.m like this
AddressBook *newAddressBook = [AddressBook new];
newAddressBook.nameArray = [NSMutableArray array];
then i could do what I want. I have successfully made a program like this but not an iPhone version.


BIDViewController.h

#import <UIKit/UIKit.h>
#import "AddressBook.h"
@interface BIDViewController : UIViewController
{
    AddressBook *myBook;
    UITextField *firstNameField;
    UITextField *lastNameField;
    NSString *tester;
    id myTempBook;

}
//@property (retain, nonatomic) AddressBook *myBook;
@property (retain, nonatomic) IBOutlet UITextField *firstNameField;
@property (retain, nonatomic) IBOutlet UITextField *lastNameField;
@property (copy, nonatomic) NSString *tester;
@property (retain, nonatomic) id myTempBook;
- (IBAction)addToAddressButton:(id)sender;
- (IBAction)textFieldDoneEditing:(id)sender;
- (IBAction)displayAddress:(id)sender;

@end

BIDViewController.m

#import "BIDViewController.h"
@implementation BIDViewController
@synthesize lastNameField, firstNameField, tester;
//@synthesize myBook;
@synthesize myTempBook;



- (IBAction)textFieldDoneEditing:(id)sender
{
    //keyboard stuff
    //give control back to view
    [sender resignFirstResponder];
}
- (IBAction)displayAddress:(id)sender
{
    //display address book array
}
- (IBAction)addToAddressButton:(id)sender
{

    //add the names to array
    //here is what I want to do
    [myBook.nameArray addObject:lastNameField.text];

    //ever time I NSLog the array with objectAtIndex:0 
    //it returns null.  I've tried EVERY combinations of stuff I even tried
    //allocating a new array
   //such as myBook.nameArray = [NSMutableArray array]; and I still could not return anything but null :( 

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

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

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

My Question:

what am I doing wrong because I have accomplished this exact same concept but running the program in main.m.

I think I understand what is going on…

  1. iPhone program loads the BIDViewController when the user clicks on the app icon.
  2. since BIDViewController gets initialized it creates myBook which is an object in class AddressBook. it is automatically getter and setter with @synthesize
  3. my BIDViewController sees that it is created and I can write to the array with no problem however somewhere along the way I keep getting null returns.

Other side notes

I can share my program where I have successfully accomplished what I wanted in a non iPhone app but a simple command console version.

  • 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-28T14:20:16+00:00Added an answer on May 28, 2026 at 2:20 pm

    At no point do you create myBook. It will always be nil, so you won’t ever be able to do anything with its array property.

    Just declaring a property and synthesising the accessors doesn’t automatically create you an object. You must create the object and assign it to your property, which you mention doing but do not have in your code.

    In addition, there seems no good reason why address book would inherit from UIViewController. It seems like a model object, it should probably inherit from NSObject.

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

Sidebar

Related Questions

Good day, I have been given an assignment that gets data off a CSV
First off I apologize... I have posted this question before, but I did a
First off I am new to FM but I have a good handle on
First off, I am using Windows XP. I have multiple hard drives and it
First off, there's a bit of background to this issue available on my blog:
First off, I'm working on an app that's written such that some of your
First off, this question is ripped out from this question. I did it because
First off, code-readability goes out the window for this question. I'm all for code
First off , my english is not very good so be nice :) My
First off, this question is not what does the constructor property do? - There's

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.