Symbyoz
  • Documentations
  • News
    • Access to Private and Public S3 bucket
    • Create manual database Backup
    • Parse Live Query on Symbyoz
    • Symbyoz back-office "white mark"
    • Cloud Code is now available in a Console
  • Tutorials
    • How to create a new project
    • How to create a custom module
    • How to manage left menu
    • How to manage admin user rights
  • Source code examples
    • Connect to iOS app
    • Connect to Android app
    • Create & Save Object
    • Get Object
    • Delete Object
    • User Management
    • Queries
    • Subclasses
    • Cloud Code
Powered by GitBook
On this page

Was this helpful?

  1. Source code examples

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:

ParseObject object = new ParseObject("ClassName");
object.put("displayName", "John Doe");
object.put("isFunny", false);
object.put("age", 50);
var object = PFObject(className:"ClassName")
object["displayName"] = "John Doe"
object["isFunny"] = false
object["age"] = 50

Into this:

ClassName object = new ClassName();
object.setDisplayName("John Doe");
object.setIsFunny(false);
object.setAge(50);
var object = ClassName()
object.displayName = "John Doe"
object.isFunny = false
object.age = 50

Creating Subclass

Follow this example to have your own subclass ready to use.

  1. Create your class as following

ClassName.java
import com.parse.ParseClassName;
import com.parse.ParseObject;

@ParseClassName("ClassName")
public class ClassName extends ParseObject
{
  public String getDisplayName() 
  {
    return getString("displayName");
  }
  
  public void setDisplayName(String value) 
  {
    put("displayName", value);
  }
}
import Foundation
import Parse

class Address: PFObject, PFSubclassing
{
    @NSManaged var media:  PFFile?
    @NSManaged var fullAddress:  String?
    @NSManaged var street:  String?
    @NSManaged var googlePlaceId:  String?
    @NSManaged var city:  String?
    @NSManaged var streetNumber:  String?
    @NSManaged var isDeleted:  Bool
    @NSManaged var owner:  PFUser?
    @NSManaged var location:  PFGeoPoint?
    @NSManaged var country:  String?
    @NSManaged var postalCode:  String?
    @NSManaged var comment:  String?
    @NSManaged var isBillingAddress:  Bool
        
    override init()
    {
        Address.registerSubclass()
        super.init()
    }
    
    static func parseClassName() -> String
    {
        return "Address"
    }
}

2. Register your class before you initialize Parse in your Application class

MyApp.java
import com.parse.Parse;
import android.app.Application;

public class MyApp extends Application 
{
  @Override
  public void onCreate() 
  {
    super.onCreate();
    
    // REGISTER SUBCLASSES HERE
    ParseObject.registerSubclass(ClassName.class);
    
    // Initialize Parse SDK (more info at "Connect to Android App")
    Parse.initialize(new Parse.Configuration.Builder(this)
      .applicationId("YOUR_APP_ID")
      .clientKey("YOUR_CLIENT_KEY")
      .server("https://xxxx.parse-symbyoz.com/parse/")
      .enableLocalDataStore()
      .build()); 
  }
}

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.

PreviousQueriesNextCloud Code

Last updated 6 years ago

Was this helpful?