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);

Into this:

ClassName object = new ClassName();
object.setDisplayName("John Doe");
object.setIsFunny(false);
object.setAge(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);
  }
}

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.

Last updated