Hissah Hissah - 1 year ago 65
Swift Question

What is the data source for filteredUsers should be in my TableViewController?

I am working on iOS project using Swift and I am trying to add a search bar to my TableViewController

This is my code:

the properties part:

var UserNamesArray: NSMutableArray = []


var filteredUsers = [UserNamesArray]()

When I add the previous line it give me an error: instance member 'UserNamesArray' cannot used on type 'MyTableVC' .

So this is the problem, what can I put instead of

viewDidLoad function:

.observeEventType(.Value, withBlock: { snapshot in
if let dict = snapshot.value as? NSMutableDictionary{
print("dict====== \(dict)")

for (key,value) in dict {
let mainDict = NSMutableDictionary()
mainDict.setObject(key, forKey: "userid")
if let dictnew = value as? NSMutableDictionary{
if let metname = dictnew["UserName"] as? String
mainDict.setObject(metname, forKey: "UserName")
if let metname = dictnew["Details"] as? String
mainDict.setObject(metname, forKey: "Details")
if let metname = dictnew["Email"] as? String
mainDict.setObject(metname, forKey: "Email")
print("mainDict========= \(mainDict)")

print("UserNamesArray ==== \(self.UserNamesArray)")


To make it clear, I took a screen shot of values of the variables:

1) dict 2) mainDict 3) UserNamesArray
Please, click here

That what my table view controller look like:

I attempted to make it clear as I can I hope that someone can help.
Thanks in advance!

Answer Source

var filteredUsers = [UserNamesArray]() doesn't work because UserNamesArray is not a valid type, it's just an object.

For example in the syntax var foo = [Bar](), Bar is the type of the objects in the array foo.

So if filteredUsers is meant to hold an array of String objects then what you want is:

var filteredUsers = [String]()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download