0

Basically, the total amount a person needs to raise is £3000, so I want that to be the starting value of money to be raised, I then want them to be able to enter how much they have raised so far. This value will be taken from the £3000 and shown on the screen, however the problem lies in how i can now get the new total value to be £3000 - the money raised, so the next time they enter their fundraised amount it subtracts form the new value.

This is what i have so far:

float mR; 
float total = (3000-mR);
mR = total-([moneyRaised.text floatValue]);

moneyRaised.text = @"";
leftToRaise.text = [[NSString alloc] initWithFormat:@"£%.2f", mR];
nhahtdh
  • 55,989
  • 15
  • 126
  • 162
  • 1
    Can you provide some examples that explain how you would like it to be displayed? And what is wrong with the code you have already? – Dan F Jun 08 '12 at 14:45
  • Are you asking how to store the value of money raised so that the next time you run this app, it remembers the previous value and subtracts an additional value? – joverboard Jun 08 '12 at 14:49
  • Yes basically it only needs to be available localy – user1440806 Jun 18 '12 at 13:52

1 Answers1

1

When addressing this question, decide not only what you want to do now, but what you may want to do in the future. If this is a one-off program for learning purposes, feel free to skip down a bit.

  • Are you going to track the transactions? (by amount? date? contributor?)
  • How many users need to be able to affect the data? (local data? SQL?)
  • Will you be adjusting the app to take in different goals? (simultaneous goals?)
  • How else might you need to view the data? (a table of entries? a list of goals?)

When designing an app, it can be overwhelming to start off with all these large-scope questions, but having a general idea for them is good when you have your proof-of-concept and need to broaden to meet your end goals.

That said, there are three ways to locally store data: NSUserDefaults, CoreData and plist. My recommendation for your data would be a plist file (one for each goal). This stores a list of key-value pairs and can be any length. If you (or your end user) is the only one who should be able to affect the data, this is a good way to go about it. There is a particularly good answer comparing the three here: Should I use NSUserDefaults or a plist to store data?

For data that needs to be available to many different users, it gets a great deal more complicated, and it really depends on your available resources, your budget, your skill, the potential number of users, etc.

If you're asking how to set up an interface to connect your provided code to, that's a different beast entirely, and I would suggest finding some basic tutorials to run through before tackling anything on your own.

Community
  • 1
  • 1
joverboard
  • 335
  • 1
  • 3
  • 13