Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-30-2011, 04:28 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 12
Peak Mobile is on a distinguished road
Default Not sure what to use for Strings w/ attributes

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.

Thanks for any help!
Peak Mobile is offline   Reply With Quote
Old 08-30-2011, 04:29 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

You could do any of that. Depends on how much of these strings you have and what kinds of attributes.
baja_yu is offline   Reply With Quote
Old 08-30-2011, 04:37 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 12
Peak Mobile is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
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?
Peak Mobile is offline   Reply With Quote
Old 08-30-2011, 05:32 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

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.
baja_yu is offline   Reply With Quote
Old 08-30-2011, 05:42 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 12
Peak Mobile is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
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.

Serbia, huh? I'm here: (46.20218, -119.15112)
Peak Mobile is offline   Reply With Quote
Old 08-30-2011, 05:57 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Peak Mobile View Post
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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-30-2011, 06:10 PM   #7 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 12
Peak Mobile is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
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.
Peak Mobile is offline   Reply With Quote
Old 08-30-2011, 08:29 PM   #8 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Peak Mobile View Post
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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-30-2011, 09:14 PM   #9 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

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.
baja_yu is offline   Reply With Quote
Old 08-31-2011, 11:24 AM   #10 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by baja_yu View Post
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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-31-2011, 11:32 AM   #11 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 12
Peak Mobile is on a distinguished road
Default

Thank you, gentlemen for all of the direction! I will try the approach you have described! I appreciate all of your help.
Peak Mobile is offline   Reply With Quote
Old 09-09-2011, 06:14 PM   #12 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 12
Peak Mobile is on a distinguished road
Default

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?

Thanks,

Andrew
Peak Mobile is offline   Reply With Quote
Old 09-09-2011, 06:22 PM   #13 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

That depends on where you're storing the array. If it's NSUserDefaults, you're fine. They'll be preserved, even backed up when syncing with iTunes.
baja_yu is offline   Reply With Quote
Old 09-09-2011, 06:25 PM   #14 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 12
Peak Mobile is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
That depends on where you're storing the array. If it's NSUserDefaults, you're fine. They'll be preserved, even backed up when syncing with iTunes.
Okay, thank you!
Peak Mobile is offline   Reply With Quote
Reply

Bookmarks

Tags
array, database, ios, string, text

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 399
5 members and 394 guests
JackReidy, jeroenkeij, Sami Gh, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:49 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0