• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSPredicates vs 'NSMutableArray's of 'NSMutableDictionary's
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPredicates vs 'NSMutableArray's of 'NSMutableDictionary's


  • Subject: NSPredicates vs 'NSMutableArray's of 'NSMutableDictionary's
  • From: William Squires <email@hidden>
  • Date: Sun, 16 Jan 2011 18:55:10 -0600

Okay, I've finally figured out how to get a UISearchBar into my iPhone app (a custom phone book for my company's internal use). Here's what I have

Model:
NSMutableArray (read from a .plist file in the bundle, then written out (1st time) to application's documents directory. Represents the list of all stores.)
  NSMutableDictionary instances (each holds the same keys, but with different values for the keys, all of which are either NSString or NSNumber - the keys are, of course, NSStrings. Each NSDictionary represents the info for a single store.)

why? Because these classes can read/write directly to/from plists. :)

View hierarchy:
UIWindow
  UIView
    UINavigationBar
      UITableView       - This is where the StoreDetailView and AddEditDetailView return to when popped off
        UISearchBar       the navController.
      StoreDetailView   \_ one of these will be pushed onto the navController when the user selects
      AddEditDetailView /  a row from the UITableView

(I may have missed one here...)

Everything worked before adding the UISearchBar. I added the UISearchBar based on info I read from one of those 'learn CocoaTouch for iOS' books... That shows up (and I've got the appropriate changes in the headers to tell my view controller that it implements UISearchBarDelegate), and implemented a stub method searchBar:textDidChange: but I don't think this is going to help. How do I turn this into an NSPredicate so I can search the model? Basically, I want something like:

    this should be an NSDictionary
        |
        v
If (array[indexPath row] valueForKey:kCompanyCode = <search text>) or (array[indexPath row] valueForKey = kStoreNum) Or (...) then
  // Use the NSPredicate to narrow the selection of rows the model will 'show' the view controller
else
  // do nothing - no matching fields for search text
end if

  Am I going to have to use CoreData to get NSPredicates to work here, or can I coerce an NSMutableArray to work if I implement some interface for searching with NSPredicates?
  At this point, I'm totally confused about how NSPredicates do their work.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Get iphoto scripting bridge handle without starting iphoto?
  • Next by Date: Thanks!
  • Previous by thread: Re: Parental Controls altering binary
  • Next by thread: Thanks!
  • Index(es):
    • Date
    • Thread