-5

I'm creating an iOS application where the user inputs a Student ID, Student Forename and Student Surname... it then stores and shows this in a table view (The data will later be uploaded to an external database) how do I go about this?

Is NSMutableDictionary even the best way to go about doing this?

Thanks

Popeye
  • 11,839
  • 9
  • 58
  • 91
steff
  • 21
  • 5
  • I have voted to close for two reasons 1) This is far to broad and 2) This question lacks any sign of research being carried out before asking the question and lacks any attempt at trying to solve this themselves and lacks any shared code to the problem they are having. – Popeye Apr 07 '14 at 12:43
  • I have researched for quite some time. I have no code to share because cant solve the problem hence coming here for some suggestions. – steff Apr 07 '14 at 12:44
  • 1
    @ste, hard to believe you found nothing on this topic. – vikingosegundo Apr 07 '14 at 12:48
  • i have searched for a day and a half now looking for a tutorial or an example on google,forums and youtube. All i need is an example/explanation on how best to do this all i want is three fields id,name, last name and it stores it in a way similar to a table... do you know where i can find an example? – steff Apr 07 '14 at 13:04
  • @steff If that's the case and you are asking for **best** why to implement this then this will really generate opinion based answers and if you are asking for tutorials of this then you are asking for off site resources both of which this question could be closed under. Just so you know I google just your title and got answers to this, so lack of research comment remains. – Popeye Apr 07 '14 at 13:13
  • i believe i have researched it but you seem to think otherwise. If you have found answers could you please post the links for me – steff Apr 07 '14 at 13:18
  • Go to http://www.google.co.uk/ enter your title. – Popeye Apr 07 '14 at 13:33
  • @Popeye i have done so and can not find a good example. Do you have one ? – steff Apr 07 '14 at 13:41

5 Answers5

2

Would be preferable if you try to implement it using the Model class. Something like this:-

@interface Student : NSObject
@property (nonatomic, retain) NSString * studentID;
@property (nonatomic, retain) NSString * studentForeName;
@property (nonatomic, retain) NSString * studentSurname;
@end

and then save the entered data to this objects and tranfer this object or collect the multiple entries to display tot he tableview.

This process will help you to add new attributes or while inserting to the DB also. Or when trying to send it to server.

Also try to follow the MVC pattern in your coding which will help you a lot for scalability.

borncrazy
  • 1,589
  • 1
  • 12
  • 9
1

If the database is going to be large, I'd suggest sqlite with CoreData. NSUserdefaults is not meant to be for large data storage but rather for small things like user settings and so on. You can store virtually everything on sqlite / core data.

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Marcal
  • 1,371
  • 5
  • 19
  • 37
0

NSDictionary/NSMutableDictionary is one of many ways. Whether or not it is the best way is up to you. You can also store it in an XML or JSON format (might be easier for uploading to a server), or even make a custom class.

Whatever you choose, I would assume that you would want to store your object (whether it be a custom class, dictionary, or xml string) in an array with other students. In that case, NSArray/NSMutableArray would be the way to go. Good luck!

user2105505
  • 686
  • 1
  • 9
  • 18
  • thanks for the help! ive had difficulty with the array approach thats why i thought about trying dictionaries...do you have any example code of nsmutable arrays with three or more fields e.g(student id,name,last name ) – steff Apr 07 '14 at 12:42
0

Depends on your server architecture but NSMutableDictionary is usually fine.

For example, if you are using a JSON server I'd go for NSMutableDictionary then convert to NSDATA and post up to a JSON server. Something like:

NSData *postData = [NSJSONSerialization dataWithJSONObject:[YOUR DICTIONARY] options:0 error:&error];
[request setHTTPBody:postData];

If you want to save the data locally use Core Data.

Peter Todd
  • 8,561
  • 3
  • 32
  • 38
-1

You can store the items individually or as an NSDictionary (the immutable one) in NSUserDefaults

to save it:

[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:YOURDICTIONARY] forKey:@"MYKEY"];  
[[NSUserDefaults standardUserDefaults] synchronize];

to get it back:

NSDictionary *mydictionary = (NSDictionary *)[NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] objectForKey:@"MYKEY"]];
  • okay so whats the best way about doing this i want in the end to be able to view on a table something along these line 1 - john - smith , 2-jodie-davies, 3-daniel-day etc – steff Apr 07 '14 at 12:38
  • Sorry but what is the point in `"NSDictionary (the immutable one)"` why not just put `NSMutableDictionary`??? – Popeye Apr 07 '14 at 12:41
  • 1) NSUserDefaults would store the dictionary immutable, even if it is an mutable one. 2) NSUserDefault is not meant to hold business data. – vikingosegundo Apr 07 '14 at 12:50
  • @user3366023 vikingosegundo has already provided a pretty good comment for downvoting. – Popeye Apr 07 '14 at 12:56
  • Thanks @Popeye , I believe, What is and what is not business data, all depends on the use case. – user3366023 Apr 07 '14 at 13:20
  • I mentioned two problems, so a debate wether it is business data or not is irrelevant. oh, and one question: why do you use the NSKeyedArchiver? – vikingosegundo Apr 07 '14 at 17:16
  • for the NSDictionary you don't have to I guess, but if you are using your own objects you have to, that is why I included it so that if the OP decided to change the dictionary to custom they have a pointer to look for next clue, also your it saves it immutable anyway, is not a reason to down vote a user with two digit karma. – user3366023 Apr 07 '14 at 19:08
  • Proposing wrong usage of NSUserDefaults is reason enough to down vote. Not mentioning that a mutable object will be saved and returned immutable is another. Not explaining the introduction of another class you often won't need a third. On stack overflow we vote on good and bad questions and answers, not on the number of digits the users reputation does have. – vikingosegundo Apr 09 '14 at 02:25