0

I am using Swift & Parse.

I have this class :

public struct Order {
    public var item: String
    public var price: Double
    public var comment: String
}

I know I can store an array of Strings or Ints. Is it possible to store an array of Orders in Parse?

To store the data i use this code :

var team = PFObject(className: "team")

team.setObject(*list of Orders*, forKey: "Players")
4
  • I think you're going to need to make Order its own class on Parse. You probably want to do the same in your client code for clarity and consistency's sake instead of the struct. Commented Jul 13, 2015 at 21:52
  • I created on Parse a custom class "Order". I did the same on my swift file too. The error is gone but when I try to set and Order Object I get a 'lldb' error. Commented Jul 13, 2015 at 22:17
  • Yeah, you can't trade an object in your Swift code for an object on Parse. You are going to need to instantiate or query for a PFObject and set its properties based off class's instance variables. You should write a method to do something like this in your API client class that takes an instance of your class and updates / creates the corresponding class on parse using some kind of unique object identifier. Commented Jul 13, 2015 at 22:21
  • Ahh.. dont understand how to do this... Can u refer me to an example? Otherwise I have to find another way. Commented Jul 13, 2015 at 22:37

1 Answer 1

1

Developers can subclass PFObject for a more native object-oriented class structure. Strongly-typed subclasses of PFObject must conform to the PFSubclassing protocol and must call before [Parse setApplicationId:clientKey:] is called. After this it will be returned by PFQuery and other PFObject factories.

In plain English for the reasonable man:

Swift

class Order : PFObject, PFSubclassing

Obj-C

@interface Order : PFObject, PFSubclassing
Sign up to request clarification or add additional context in comments.

Comments

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.