ios - Compare dictionary keys with array to extract matching and non matching data -


i trying retrieve facebook friends list , display user if following users or not. using facebookid's stored on parse backend , when user clicks on follow button, add facebookid key value "following" in parse. later retrieve following key array , display user currentuser following or not following.

my friend list:

var friend = ["902165525": "john", "10204125099": "sam", "153822": "sandy", "475585616": "nito"] 

i following:

var follow = ["10204125099", "153822"] 

now want extract friend array can see friends "not following" i.e else block.

wanttogetthis -> ["902165525": "john", "475585616": "nito"] 

what have is,

    func check() {      in self.follow {          (key, value) in friend {              if key.containsstring(all) {                  print("yes: \(key), \(value)")              } else {                 print("no: \(key), \(value)")              }         }     } } 

this if loop

yes: 10204125099, sam  yes: 153822, sandy 

this else loop

no: 153822, sandy  no: 902165525, john  no: 475585616, nito  no: 902165525, john  no: 10204125099, sam  no: 475585616, nito 

why getting sandy , sam in else block , multiple john , nito? wrong in here?

you should not print in inner loop. instead should use see if item matches current 1 outer loop, , print result after loop over:

for (key, value) in friend {     var found = false     in self.follow {         if key == {             found = true             break         }     }     if found {         print("yes: \(key), \(value)")     } else {         print("no: \(key), \(value)")     } } 

note order of loops should changed well: inner loop should become outer, retain access key , value after inner loop over.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -