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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:52:36+00:00 2026-06-06T06:52:36+00:00

I’m trying to create an app (my first) that generates invoices for me. Originally

  • 0

I’m trying to create an app (my first) that generates invoices for me. Originally my idea was to have the following classes:

  • User (who all of the following application data belongs to)
  • Customer (who to bill: Name, CompanyName, BillingAddress,
    Phone, etc…)
  • Task (a line item on the invoice: Name, Description,
    HourlyRate, etc…)
  • Invoice (the final output that is comprised of a Customer and
    multiple Tasks)

I thought I could have the user select “Add new customer”, which would create a Customer object and then store that object into a customer array. Same thing with “Add a new task”, which would create a Task object and add it to a task array. I would then be able to create an Invoice object that points to a certain value in the customer array and multiple tasks in the tasks array.

The problem I am running into is that I don’t know how to create a new object each time someone presses “Add New Customer” or “Add a new task”. I’ve tried doing something like this:

Customer *customer = [[Customer alloc] init];
[customer setName:@"John Doe"];
[customer setCompanyName:@"John's Swimming Pools"];

[user1 addCustomer:customer];

[customer setName:@"Jane Smith"];
[customer setCompanyName:@"Cupcakes by Jane"];

[user1 addCustomer:customer];

for (int i = 0; i < [[user1 customers] count]; i++) {
    NSLog(@"%@",[[[user1 customers] objectAtIndex:i] name]);
}

I realize this doesn’t work because the pointer to customer is being overwritten with Jane, so when the array is printed both values in it say “Jane Smith”.

How can I create a new pointer to an object every time the user decides to add a customer/task? Or am I going about this all wrong and should be using arrays for everything instead of classes? I feel like this is very basic OOP and I am struggling to wrap my head around it. Any help would be greatly appreciated, thank you!

  • 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-06T06:52:38+00:00Added an answer on June 6, 2026 at 6:52 am

    If each time some one presses and only one customer is added then why you are adding it twice in the same place?
    A simple factory method for adding a customer could be defined in customer class.
    At first declare it in Customer.h like:

    +(Customer*)createCustomerWithName:(NSString*)name AndCompany:(NSString*)cp;
    

    Then in .m :

    +(Customer*)createCustomerWithName:(NSString*)name AndCompany:(NSString*)cp
    {
       Customer *customer = [[Customer alloc] init];
       [customer setName:name];
       [customer setCompanyName:cp];
       return customer;
    }
    

    Then in your code when you need to add a customer, just call:

    [user1 addCustomer:[Customer createCustomerWithName:@"ALan" AndCompany:@"MS"]];
    

    And call it any times you want. Your problem should be solved.

    N.B. You must import Customer.h in your class where you call this factory method.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

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.