realm / realm-browser-osx

DEPRECATED - Realm Browser for Mac OS X has been replaced by realm-studio which is cross platform.
https://realm.io
502 stars 54 forks source link

Exporting List Models To Swift #367

Closed nallick closed 6 years ago

nallick commented 6 years ago

If the following Node.js code is used to create and populate a realm, then the Realm Browser 3.0.1 (98) is used to save the model definitions to Swift, rather than exporting a list (e.g., let values = List()), it produces an error "Error! 'Any' properties are unsupported in Swift."

const SchemaTestReadOnlySchema = {
    name: 'SchemaTestReadOnly',
    properties: {
      values: 'SchemaTestElement[]'
    }
};

const SchemaTestElementSchema = {
    name: 'SchemaTestElement',
    properties: {
      value: 'int'
    }
};

async function populateSchemaTest(loginUrl: string, realmUrl: string, adminUserName: string, adminUserPassword: string) {
    const adminUser = await Realm.Sync.User.login(loginUrl, adminUserName, adminUserPassword);
    const config = {
        schema: [SchemaTestElementSchema, SchemaTestReadOnlySchema],
        sync: {
            url: realmUrl + "/schema_test_readonly",
            user: adminUser,
        },
    };
    const realm = await Realm.open(config);
    const permissionChange = await adminUser.applyPermissions({userId: "*"}, config.sync.url, "read");
    realm.write(() => {
        const element1 = realm.create("SchemaTestElement", {value: 1});
        const element2 = realm.create("SchemaTestElement", {value: 2});
        const element3 = realm.create("SchemaTestElement", {value: 3});
        const schemaTest = realm.create("SchemaTestReadOnly", {values: [element1, element2, element3]});
    });
}

import Foundation
import RealmSwift

class SchemaTestElement: Object {
  dynamic var value = 0
}

class SchemaTestReadOnly: Object {
  /* Error! 'Any' properties are unsupported in Swift. */
}
bmunkholm commented 6 years ago

That's a bug. It has been fixed in the upcoming release of Realm Studio that will be released soon. In the meantime, you will have to fix it manually in the model.

ianpward commented 6 years ago

should be fixed now