Subclasses
Subclassing is completely optional, however it has many advantages, including terseness, extensibility, and support for autocomplete. In Symbyoz you can automatically generate subclasses of your Modules, in Swift and Java , from the Configuration section of your backend.
It will literally transforms this code:
Java
Swift
1
ParseObject object = new ParseObject("ClassName");
2
object.put("displayName", "John Doe");
3
object.put("isFunny", false);
4
object.put("age", 50);
Copied!
1
var object = PFObject(className:"ClassName")
2
object["displayName"] = "John Doe"
3
object["isFunny"] = false
4
object["age"] = 50
Copied!
Into this:
Java
Swift
1
ClassName object = new ClassName();
2
object.setDisplayName("John Doe");
3
object.setIsFunny(false);
4
object.setAge(50);
Copied!
1
var object = ClassName()
2
object.displayName = "John Doe"
3
object.isFunny = false
4
object.age = 50
Copied!

Creating Subclass

Follow this example to have your own subclass ready to use.
  1. 1.
    Create your class as following
Java
Swift
ClassName.java
1
import com.parse.ParseClassName;
2
import com.parse.ParseObject;
3
4
@ParseClassName("ClassName")
5
public class ClassName extends ParseObject
6
{
7
public String getDisplayName()
8
{
9
return getString("displayName");
10
}
11
12
public void setDisplayName(String value)
13
{
14
put("displayName", value);
15
}
16
}
Copied!
1
import Foundation
2
import Parse
3
4
class Address: PFObject, PFSubclassing
5
{
6
@NSManaged var media: PFFile?
7
@NSManaged var fullAddress: String?
8
@NSManaged var street: String?
9
@NSManaged var googlePlaceId: String?
10
@NSManaged var city: String?
11
@NSManaged var streetNumber: String?
12
@NSManaged var isDeleted: Bool
13
@NSManaged var owner: PFUser?
14
@NSManaged var location: PFGeoPoint?
15
@NSManaged var country: String?
16
@NSManaged var postalCode: String?
17
@NSManaged var comment: String?
18
@NSManaged var isBillingAddress: Bool
19
20
override init()
21
{
22
Address.registerSubclass()
23
super.init()
24
}
25
26
static func parseClassName() -> String
27
{
28
return "Address"
29
}
30
}
Copied!
2. Register your class before you initialize Parse in your Application class
Java
MyApp.java
1
import com.parse.Parse;
2
import android.app.Application;
3
4
public class MyApp extends Application
5
{
6
@Override
7
public void onCreate()
8
{
9
super.onCreate();
10
11
// REGISTER SUBCLASSES HERE
12
ParseObject.registerSubclass(ClassName.class);
13
14
// Initialize Parse SDK (more info at "Connect to Android App")
15
Parse.initialize(new Parse.Configuration.Builder(this)
16
.applicationId("YOUR_APP_ID")
17
.clientKey("YOUR_CLIENT_KEY")
18
.server("https://xxxx.parse-symbyoz.com/parse/")
19
.enableLocalDataStore()
20
.build());
21
}
22
}
Copied!
And you're all done!
Now you can simply use it as you would use any other Object but with a structured model and accessor added.
Copy link