1

I tried to filter my class array but I keep getting an error and I have no idea why

this is my code :

var shops = [Shops]()

and the when I get data from server and save them

 let desgin = subJson["desgin"].stringValue

 let familiy_id = subJson["id"].stringValue


 var info = Shops(shopname: shopName, Logo: logoString, family_id: familiy_id , design : desgin )

self.shops.append(info)

value of tuple string json has no member design

I'm trying to filter the shops with design. Shops is where I save the data coming as JSON

class Shop {
    ...
 var design: String?
    ...
}
11
  • can you show your json? does it have member design? Commented Sep 16, 2017 at 16:37
  • check my code again Commented Sep 16, 2017 at 16:39
  • @leo0019 where is Shops declared? Commented Sep 16, 2017 at 16:40
  • I think problem is this line Shops(shopname: shopName, Logo: logoString, family_id: familiy_id , design : desgin ) here you are using Shops but your class name is Shop Commented Sep 16, 2017 at 16:41
  • I declare shops before getting data Commented Sep 16, 2017 at 16:42

1 Answer 1

3

I think problem is this line

 var shops = [Shops]()

and this line

 Shops(shopname: shopName, Logo: logoString, family_id: familiy_id , design : desgin )

You are using Shops to make an object and you are filtering according to Shop class

Your code should be this:

var shops = [Shop]()


 let desgin = subJson["desgin"].stringValue

 let familiy_id = subJson["id"].stringValue


 var info = Shop(shopname: shopName, Logo: logoString, family_id: familiy_id , design : desgin )

self.shops.append(info)

let filteredArr = self.shops.filter { $0.design != nil }

here is your class Shop

class Shop {
    ...
 var design: String?
    ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

perfect answer!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.