0

Background

  • Parse 1.8.5 iOS SDK
  • Xcode 7.0.1 (7A1001)
  • Swift 2

In my code, I subclassed PFUser (named as MyUser), and try to create the query using MyUser.query(). It returns me PFQuery?

let query = MyUser.query()
query!.whereKey("username", containedIn: ["a", "b"])
query!.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
  ...
})

I then submitted this to App Store Review, and being rejected 4 times (taking me 4 weeks), and they kept reporting the app crashes around here. It's been very frustrating. After checking with Crashlytics, it says the below line is raising EXC_BREAKPOINT.

query!.whereKey("username", containedIn: ["a", "b"])

The crash log from Apple says it is EXC_BREAKPOINT (SIGTRAP), that implies a non-optional type with a nil value according to TN2151. In fact the symbolicated version of the crash logs provided by Apple shows line number to be 0.

I checked Parse documentation, the returned PFQuery is not optional. I wonder what is the best practice to implement this logic.

Harry Ng
  • 1,070
  • 8
  • 20

1 Answers1

0

I have not tried to subclass a PFObject before but as I checked the documentation, the query method (PF_NULLABLE PFQuery *)query clearly returns a Nullable PFQuery object which will be treated by Swift as an optional. (see here) It also says that the subclass can only call this method if it conforms to PFSubclassing protocol.

Generally when there is an optional, you really need something like an if let to protect yourself against a nil being returned.

Mo Nazemi
  • 2,618
  • 2
  • 16
  • 23