【问题标题】:Xamarin.ios and Realm issue with creating realm object创建领域对象的 Xamarin.ios 和领域问题
【发布时间】:2018-05-14 14:29:23
【问题描述】:

我第一次在 Xamarin.ios 平台上使用 Realm 时遇到问题。我正在关注本教程:Realm and Xamarin Tutorial

我遇到的问题是,当我尝试使用 realm.CreateObject() 创建对象时。我收到一条错误消息“非泛型方法 'Realm.CreateObject(string, object)' 不能与类型参数一起使用”

我在死胡同,不知道从这里做什么。我完全按照教程进行了操作,但此时仍然无法正常工作。

ViewController 代码:

private void AddNewCar()
    {
        var realm = Realm.GetInstance();

        realm.Write(() =>
        {
            var newCar = realm.CreateObject<Car>(); //This is where it has an error

        });


    }

这是我在另一个类文件中的公共类:

using System;
using Realms;

namespace RealmApp.Model
{
    public class Car: RealmObject
    {
        public string Brand { get; set; }
        public string Model { get; set; }

        public Car()
        {

        }
    }
}

希望有人可以提供帮助! 杰米

【问题讨论】:

    标签: c# ios xamarin.ios realm


    【解决方案1】:

    把你的 realm.CreateObject 改成这个。 realm.Add(new Car { Brand = "Your Brand", Model = "Your model" });

    您也可以在 Add 之外创建模型,只需执行 realm.Add(yourModel)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多