Search Within Array Object in Swift

Search Within Array Object in Swift

By : wiesel
Date : November 18 2020, 03:49 PM
To fix this issue I have an array of restaurants that are objects with name, type, location, etc. How can I search for just a restaurant name, or just a location without searching the entire array object? , You can use filteredArrayUsingPredicate. Here is the small example:
code :
NSString *searchString = @"a";
NSArray *filteredProducts = [products filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"title CONTAINS[cd] %@", searchString]];
let searchString = "text_to_search"
let predicate = NSPredicate(format: "title CONTAINS[cd] %@", searchString);
let filteredArray = array.filteredArrayUsingPredicate(predicate!);

Share : facebook icon twitter icon
Search an array based on search text using Swift

Search an array based on search text using Swift

By : user3494689
Date : March 29 2020, 07:55 AM
hop of those help? A search corresponding to the predicate operator "CONTAINS[c]" can be achieved with rangeOfString() with the .CaseInsensitiveSearch option:
code :
let searchText = "MITH"

let filtered = nameList.filter {
    return $0["firstName"]?.rangeOfString(searchText, options: .CaseInsensitiveSearch) != nil

// Result: [[firstName: Smith, lastName: Green]]
let filtered = nameList.filter {
    return $0["firstName"]?.range(of: searchText, options: .caseInsensitive) != nil
Search in object array in Swift

Search in object array in Swift

By : maud L
Date : March 29 2020, 07:55 AM
it fixes the issue You can use the filter method on arrays to find matches. Since your array properties are optional this needs to be considered as well and I filtered first on .fat since it's the cheapest performance vice.
code :
let result = productsTmpObjectArray.filter {($0.fat == 8) &&
   $0.temporaryPodSegmentyRynku?.contains("DANIE_GLOWNE") && 
   $0.temporaryConcepts?.contains("SHARE_THE_FUN") && 
   $0.temporarySegmentyRynku?.contains("HOTEL") }

let result2 = productsTmpObjectArray.filter { $0.prepDeepFryer?.isEmpty }
Search a string array with substrings contained in the array Swift 4.x

Search a string array with substrings contained in the array Swift 4.x

By : Joshua Crouch
Date : March 29 2020, 07:55 AM
Any of those help This gives you all elements with a duplicate prefix into an unidimensional array:
code :
var elements = ["A2A1", "A1A2", "A1B1", "B1A1", "B1C1", "C1B1", "D3E3", "E4E3", "E3D3", "E3E4"]

let elementsWithDupPrefix = elements.filter { (str) -> Bool in
    let prefix = String(str.prefix(2))
    return elements.firstIndex(where: { $0.hasPrefix(prefix) }) != elements.lastIndex(where: { $0.hasPrefix(prefix) })
Show master array results, based on nested array element search in swift

Show master array results, based on nested array element search in swift

By : user2641006
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have set of example data , This should do the trick:
code :
let text = "The iPhone"
let filteredSections = sectionsData.compactMap({ (aSection) -> Section? in
    let keptItems = aSection.items.filter({ $0.detail.contains(text) })
    if keptItems.isEmpty {
        return nil
    } else {
        return Section(name: aSection.name, items: keptItems, collapsed: aSection.collapsed)
How to Search an array of object in Swift 3

How to Search an array of object in Swift 3

By : anweshi
Date : March 29 2020, 07:55 AM
wish helps you I am trying to search an array of objects that I'm pulling from a Firebase database. The data is loading fine but when I try to search nothing shows. I've only been learning iOS/Swift development for about 6 weeks now. Below is code I have. , if your Service class is as follows
Related Posts Related Posts :
  • NSRunLoop API difference
  • Is it possible to inject custom settings into my iOS application "Notifications" settings dialog?
  • UIAlertview not accepting string as message
  • Axis change of stackView giving layout error
  • How to use AVAssetResourceLoader?
  • How to write block definition using properties?
  • iOS connect/reconnect to Bluetooth device when using external-accessory and MFi
  • Saving XMPP Multi User chat messages through XMPP MessageArchiving in iOS
  • Deciding iOS version: pros and cons
  • iOS: Resigned app cannot access keychain through security API
  • How can I set To and Subject fields in an E-Mail being sent by UIDocumentInteractionController?
  • Updating uilabel in view controller underneath another
  • Maximum time Intervel for NSTimer
  • Delete Core Data Entry from Table View Controller
  • How to unload UIViewcontroller from memory?
  • Compressing UIImage as Far as Possible?
  • Optimizing workflow to update internally owned cocoapods dependencies?
  • Formatting an NSDate with Abbreviated Month/Day Names
  • I'm creating a quiz game with 4 answers and I want to add score
  • Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • How to change the UILabel content by tapping?
  • Adding checkmark to selected table cell also checks another table cell
  • UICollectionView cellForItemAtIndexPath indexPath row is nil
  • Resize and set quality on JPEG image while retaining EXIF in iOS
  • How to push rootviewcontroller in Ios
  • How to add UIBarbuttonItem at centre on UInavigationbar in iOS
  • Would this IOS device test crash be expected
  • PickerView not showing any values
  • How to set root view controller in storyboard animated with navigation controller programmatically
  • Can anyone suggest me the effective way to deal with s3 upload fail because of timezone difference issue?
  • Getting list of files in documents folder
  • Error while using Realm Object as a singleton. Is it a good idea?
  • inserting into SQLite database
  • More nodes than I should
  • Facebook IOS SDK navigate to another controller after login not working
  • Swift Array - use "Contains" of type AnyObject
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org