Can anyone point me in the right direction. I am working on an app that displays different text strings. I want to be able to cylce through my text strings with a previous/random/next buttons, be able to share the text string, and to be able to mark it as a favorite.
Do I use an array or a database or what to create text strings with these attributes and be able to display different indexed strings, and display strings that have some sort of boolean for the favorite.
You could do any of that. Depends on how much of these strings you have and what kinds of attributes.
I plan on having 6 categories of textstrings with 30-50 strings. I want to cycle through the text strings within a category, or cycle through all text strings that have been marked "favorite". So I'm guessing I need some sort of unique identifier, a boolean for the favorite, and an index to control the previous/random/next controls. Is that somewhat accurate?
The simplest way might be to make a container class, which would have attributes like: text (NSString), category (NSString), favorite (BOOL) etc, then have an array which would hold objects of this custom class.
The simplest way might be to make a container class, which would have attributes like: text (NSString), category (NSString), favorite (BOOL) etc, then have an array which would hold objects of this custom class.
Thanks for the direction! I'll start researching container classes.
I plan on having 6 categories of textstrings with 30-50 strings. I want to cycle through the text strings within a category, or cycle through all text strings that have been marked "favorite". So I'm guessing I need some sort of unique identifier, a boolean for the favorite, and an index to control the previous/random/next controls. Is that somewhat accurate?
If you're going to have different categories of strings, and favorites, and want the user to be able to sort and filter the strings on demand, you might want to look into Core Data. It's very powerful, and makes it pretty easy to display your data in a table view sliced and diced as desired. Core Data is a pretty big, complex framework, though, and I found it a challenge to get my head around using it. Once I waded through it, and got it working, I was amazed at how powerful it was and how easy it was to add very advanced features to my apps. The learning curve is steep, however.
You could also use NSPredicates for filtering and NSSortDescriptors for sorting an NSMutableArray. That would be much simpler for a small database that only holds 30-50 string objects.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
If you're going to have different categories of strings, and favorites, and want the user to be able to sort and filter the strings on demand, you might want to look into Core Data. It's very powerful, and makes it pretty easy to display your data in a table view sliced and diced as desired. Core Data is a pretty big, complex framework, though, and I found it a challenge to get my head around using it. Once I waded through it, and got it working, I was amazed at how powerful it was and how easy it was to add very advanced features to my apps. The learning curve is steep, however.
You could also use NSPredicates for filtering and NSSortDescriptors for sorting an NSMutableArray. That would be much simpler for a small database that only holds 30-50 string objects.
Can you only display Core Data in a table view? I am wanting to display one string at a time, by cycle through a subset of all of my data, sorting by one of the six categories.
It sounds like filtering my content into an Array would be easiest to handle.
Can you only display Core Data in a table view? I am wanting to display one string at a time, by cycle through a subset of all of my data, sorting by one of the six categories.
It sounds like filtering my content into an Array would be easiest to handle.
No, you can use Core Data in lots of different ways. It just makes it very easy to present the results in a table view.
One string at a time, I would just use an array and an NSPredicate to filter, and NSSortDescriptor to sort it.
NSMutableArray has methods like sortUsingDescriptors and filterUsingPredicate that let you sort/filter the array. You can also use the method filteredArrayUsingPredicate to leave the original array intact, and produce a second array that contains only the item(s) that meet your filter criteria.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Being that your objects will only contain some strings and you wont have a lot of them, it would be easiest to just pull them all into an array, then go through the array using an index to show them one by one. Core Data is great, but it does have a somewhat steeper learning curve. If you have the time, now might be a good chance to learn in, and with such a simple task. It will definitely pay off in the future.
If you decide to go the other way, just create a new class (subclass of NSObject) and add a few properties to it: text, category, isFavorite etc. Your class will probably do nothing (no methods), just be a container for data. Then you alloc/init an instance of it, set the properties to what you want, and add it to the array.
Being that your objects will only contain some strings and you wont have a lot of them, it would be easiest to just pull them all into an array, then go through the array using an index to show them one by one. Core Data is great, but it does have a somewhat steeper learning curve. If you have the time, now might be a good chance to learn in, and with such a simple task. It will definitely pay off in the future.
If you decide to go the other way, just create a new class (subclass of NSObject) and add a few properties to it: text, category, isFavorite etc. Your class will probably do nothing (no methods), just be a container for data. Then you alloc/init an instance of it, set the properties to what you want, and add it to the array.
I agree with Baja. Your task is really, really simple. Core Data would be overkill.
Create a data container object that holds a string and your different settings (string item name, category of item, a flag that indicates if it's a favorite, etc.)
Create a mutable array of these items. Then either loop through the array manually (for a short array) or use the different sorting and filtering methods I mentioned in a previous post (filterUsingPredicate and sortUsingDescriptors). Problem solved, and with only a few lines of code.
Expect to spend a week figuring out Core Data if you decide to go that route. It will be a week well spent in terms of building your skill-set, but not an effective way to solve this particular task.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Question: Under this approach will the users' favorites be wiped clean with an update to the code? What will make the users modifications to the NSMutableArray persist through application updates?