ios


Searching for a substring in string in Swift not working


I am matching an substring in my suggestion array to make a Autocomplete text field.
func searchAutocompleteEntriesWithSubstring(substring: String)
{
autocompleteUrls.removeAll(keepCapacity: false)
for curString in countries
{
let myString:NSString! = curString as NSString
let substringRange :NSRange! = myString.rangeOfString(substring)
if (substringRange.location == 0)
{
autocompleteUrls.append(curString)
}
}
autocompleteTableView.reloadData()
}
But if the country I am searching is India and I start searching from "ndia", its not getting the suggestions, it should get that as well.
Use predicate instead:
let countries = ["india", "japan", "Indonesia", "bangladesh", "Australia"];
let predicate = NSPredicate(format: "SELF contains[c] %#", "ndia")
let autocompleteUrls = countries.filter { predicate.evaluateWithObject($0) }
print(autocompleteUrls) // output: ["india"]
if (myString.rangeOfString(substring) != nil)
{
print("hello")
}

Related Links

Parse sync of deleted objects
Invalid product
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) on uitextfield
Save files from iOS share extension for use by host app
Facebook FBSDKLoginManager/logInWithReadPermissions Swift Example not using Parse
Mix colour in Sprite Kit
Time and date for camera photos
Why Xcode 7 shows around 12% code coverage when there are no unit tests at all?
XCode iOS - How to animate position of a UICollectionView? (Slide in from bottom of screen)
iOS Swift appending value to array
How can I add different line spacing for different parts of NSAttributedString?
Xcode- Implicit conversion from long long to long changes value from 10,000,000,000,000 to 1,575,856,128
HealthKit: save samples of type HKCategoryTypeIdentifierAppleStandHour
Autoresizing UICollectionView: first UICollectionViewCell overlaps
UIAlertView' was deprecated in iOS 9.0
UIWebView enable zoom and disable scroll

Categories

HOME
math
mocking
vb.net
jsp
demandware
magento
haskell-stack
linear-programming
feed
android-sms
geany
android-dialer
wget
boxfuse
zend-expressive
ellipse
rebus
rgb
imp
amadeus
embed
garmin
html-email
lexikjwtauthbundle
hp-alm
dotnetbar
pwm
shape
google-oauth2
scalability
popupwindow
svn2git
debugview
charts.js
machine-language
folly
ubuntu-server
uistoryboardsegue
ipod-touch
logicblox
mamp-pro
tern
program-slicing
adsutil.vbs
dependency-management
strip-tags
psycopg2
orchestrate
glfw
postmark
jsbin
agents-jade
dms
administrator
membership
sqlj
sejda
tun
core-data-migration
polygons
xsb
base-conversion
windows-universal
targetinvocationexception
android-design-library
mysql5
office-2010
before-save
nhunspell
junit-runner
dfsort
data-dictionary
parsekit
external-dependencies
scrollpane
sparc
geometry-surface
google-authorship
tempo
oncreate
ed
b-method
facebook-authentication
eye-detection
keylogger
program-transformation
chickenfoot
coords

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App