2

After I updated Xcode to 7.0 (and Swift 2.0) my app no longer accepts one of my Parse statements. I have a standard Parse query. Within that query I have the following block of code:

for user in users! {
                            if !contains(accepted, user.username) && !contains(rejected, user.username){

                                self.usernames.append(user.username)
                                self.users.append(user as! PFUser)

                                if let data = user["image"] as? NSData {
                                    self.userImages.append(data)
                                }
                            }

I get the following error on user.username in the code above:

Value of type 'PFObject' has no member 'username'

I tried removing/readding the Parse SDK but no luck. I even edited the PFObject.h header file (a solution I found on another SO post) but that didn't work either. Any ideas? Did Parse SDK implementation change with Xcode 7? Am I missing something?

Thanks!!

EDIT: gist of full code: https://gist.github.com/jtansley/6c2bb4b8cb82459b8c10

kRiZ
  • 2,320
  • 4
  • 28
  • 39
winston
  • 3,000
  • 11
  • 44
  • 75
  • 1
    Seems like your `users` is a collection of `PFObject`s and not `PFUser`s – kRiZ Sep 21 '15 at 14:16
  • Thanks for the reply! I initialized the collection as PFUser. How can I fix this? Not sure why it sees this as PFObject. See full gist here: https://gist.github.com/jtansley/6c2bb4b8cb82459b8c10 – winston Sep 21 '15 at 14:29
  • I'm not an expert on Swift, but see if my answer below helps. – kRiZ Sep 21 '15 at 14:40

1 Answers1

0

Try the following:

if let users = users as? [PFUser] {
  for user in users {
    ...
  }
}

UPDATE:

Something like the following:

if !accepted.contains(user.username) && !rejected.contains(user.username)
kRiZ
  • 2,320
  • 4
  • 28
  • 39
  • I think this might be working, not sure. I'm getting a new error on line ` if !contains(accepted, user.username!) && !contains(rejected, user.username!)`. I get error `'contains' in unavailable: call the 'contains()' method on the sequence`. Any idea what this means? – winston Sep 21 '15 at 14:54
  • Tried to change it to `user.contains(accepted, user.username)` after looking at this answer http://stackoverflow.com/questions/30839733/cant-use-contains-in-swift2-using-xcode-7 but still no luck, says PFUser has no member 'contains' – winston Sep 21 '15 at 14:57
  • `Cannot invoke 'contains' with an argument list of type ([String],String)'`. I'll accept this answer because I think you fixed the original issue. Just seems like now I'm uncovering more and more issues with outdated code now that Xcode 7 is out – winston Sep 21 '15 at 15:05
  • Seems like you are passing two parameters to the `contains` function. See update to my answer. – kRiZ Sep 21 '15 at 15:16