Class specific data - iphone

using xcode I would like to achieve a public shared class that stores its own data. So, if I'm in one class I can call it from another and retain persistence.
For example,
I have multiple viewcontrollers for an iPhone project. When the app is opened, it checks with a seperate service if that player is logged in and returns some information. Let's call it GamePlacenta. I need to store certain information about the player in the GamePlacenta class, like user_id etc. But I need to be able to access it from any other class later on. I don't want to store it in text files, memory is good.
What do I need to be looking into?

You need to use a Singleton. It does exactly what you want it to--holds one set of data that you can access anywhere. Here is a great tutorial on creating one. It's just a few lines of code, and can store anything.

Sounds like you need a Singleton class. See this Wikipedia article.

Related

Is creating an object player with email and name attributes the way to go when storing name and email in a list of arrays?

I'm trying to find the cleanest solution for this before I start with this and was wondering which approach I should take. Another possible solution would be for me to store an array with all the details, such as name and email at this point, in another array.
Basically I want a list of people's names and their corresponding email address with scalability so I can increase it later. I just would like to know what is a clean way to do this.
Following the proper MVC architecture, you should create the modal classes and store the data in their instances.
It is also scalable as on later you want to add one more field you just have to add one more class member in the modal class.
You can refer to this link where i have specified how to store and retrieve data using data modal classes:

iOS iPhone MVC basics

Does anyone know of a good way to start with a basic model but not use Core Data yet? I have a simple application that doesn't need to save any data (at the moment), but I don't think Core Data would be overkill for it.
I don't want to use the App Delegate to store data, nor do I want to store data in individual views. I was hoping to find some sort of "transitioning" type of solution that would let me switch over to Core Data in the future.
I've seen some simple examples, but they require storing an instance of the model within a particular view controller. I plan to have several views, so I want to find a better way.
The data model for an app can be as simple as a dictionary, or an array of dictionaries, or a plain old C-style array of characters for that matter. Or, to take it one step further, you might create a custom model class that not only stores the data but also knows how to manipulate it as necessary for your application.
How each controller gets access to the model is a different question. Some people like to use a singleton (I don't) so that they can access it globally. A (IMO) better approach is to instantiate the model in an object like the app delegate or root view controller, and then pass either a pointer to the entire model or a pointer to part of the model to view controllers as needed. An address book app might pass just a Person object to an address detail view controller, for example.

iphone: Caching an NSMutableArray?

I'm currently writing a Twitter client for iPhone and need a way to cache the public timeline. The data fetched is stored as 'Status' objects in an NSMutableArray.
The NSMutableArray stores 20 objects at a time.
What is the best way to do this?
You will probably want to use Core Data. You'll need to create an entity for each tweet, and then store that in your database. There is quite a lot of documentation and sample code on Core Data out there; start at Apple's Samples page.
If you don't want to play with one of the frameworks already mentioned (SQLitePersistentObjects and CoreData), you could implement your own using the NSCoding protocol on your status objects. The array should already implement NSCoding for archiving/unarchiving.
If you want to start quickly try SQLitePersistentObjects.
If you never plan to go over 20 objects you could (slightly) violate some rules from the gods of apple, and use NSUserDefaults - likely the easiest one to implement, but as the name implies, made for things like user settings, so don't use for big piles of info.
Disclaimer: If you know how to use the others, use them, this one is kinda the lazy way if you don't want to learn something better but more difficult.

How do I create a development tool to create custom object instances for iphone os

I'm setting out to create an app where it will use 7-10 instances of a custom class, lets call them "books" each class will consist of a number of pages, a title, a int of how many pages a book contains and possibly some notes of the author associated with a specific page.
My question is what is the best way of creating these objects. it seems weak to just hard-code all the books together programatically, and if there are more added after the initial release I'd almost like to have the author be able to construct them with a simple desktop app.
So I guess what I'm looking for is a way to a create a small app to create instances of a custom class on a desktop, then bring those instances into the iphone app.
I only have an iphone dev license as far as I know. Obviously you don't have to be super specific but I'm looking for ways to accomplish this type of task. Maybe if there is a good way to go about hard coding them I would like to hear about that as well.
I guess an equivalent would be a game developer making like a level editor for his game so he doesn't have to create the boards programatically.
Provide your data in XML or JSON
format (or whatever flavour of file
format you prefer), this is to transfer data to/from application.
Parse your data file (xml/json) and store in permanent storage (file,sqlite,core data) on phone. This is the data that your application will regularly use from now on.
Offer user the option to get updates over network
If user selects to get updates, download updated xml/jason file over network, parse and update your permanent store
Use SQLite. You could easily create a sqlite database editor, or use some of the free ones out there. The iPhone can read a sqlite database natively, just include the library.

What's the preferred way of dealing with variables in constant use in an iPhone app?

What's the best way of dealing with variables in constant use in an iPhone app, like username/password in a twitter client?
If you are using them all over, you can store them in either the AppDelegate or an object referred to by the app delegate.
Another popular option if the data is only needed by a small section of the app, is to create a singleton class where you ask it for the current instance and store what you need there.
If you'd like the data to persist, then you really want to use either a database (CoreData is nice) or NSUserDefaults to hold values. Since you mentioned twitter usernames/passwords specifically, note that you should really hold onto data like that in the keychain, so that it is stored in encrypted form.