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
Copy ParseObject object = new ParseObject( "ClassName" ) ;
object . put ( "displayName" , "John Doe" );
object . put ( "isFunny" , false );
object . put ( "age" , 50 );
Copy var object = PFObject ( className : "ClassName" )
object [ "displayName" ] = "John Doe"
object [ "isFunny" ] = false
object [ "age" ] = 50
Into this:
Java Swift
Copy ClassName object = new ClassName() ;
object . setDisplayName ( "John Doe" );
object . setIsFunny ( false );
object . setAge ( 50 );
Copy 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.
Create your class as following
Java Swift
Copy 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) ;
}
}
Copy 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
Java
Copy 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.