首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当尝试添加和保存对象时,领域抛出错误。

当尝试添加和保存对象时,领域抛出错误。
EN

Stack Overflow用户
提问于 2019-04-26 11:06:03
回答 3查看 683关注 0票数 2

我正在用领域库开发iOS应用程序,它工作得很好。

但是当我试图保存一个模型时,它会像这样抛出错误。

终止应用程序,原因:“目标表行索引超出范围”

这是密码。

代码语言:javascript
复制
....
do {
    try realm?.write {
        let newPatientImage = PatientImage()
        newPatientImage.path = imageName
        if let flap = flap {
            newPatientImage.setStronglyTypedFlap(flap)
        }
        newPatientImage.hasPhoto = hasPhoto
        newPatientImage.flap?.flapLocationRaw = flapLocation.rawValue
        newPatientImage.id = newPatientImage.incrementalID()
            patient.patientImages.append(newPatientImage)
            realm?.add(newPatientImage)
            realm?.add(patient, update: true)
    }
} catch {

}
...

这是newPatientImage对象。

代码语言:javascript
复制
PatientImage {
    id = 22;
    hasPhoto = 0;
    isPostOp = 0;
    path = 4426699712;
    date = 2019-04-26 11:32:15 +0000;
    flap = RhomboidAFlap {
        id = 1;
        name = Rhomboid A;
        adjustables = List<Adjustable> <0x280b5c120> (
            [0] Adjustable {
                value = 60;
                defaultValue = 60;
                name = A;
                isDegrees = 1;
            },
            [1] Adjustable {
                value = 60;
                defaultValue = 60;
                name = B;
                isDegrees = 1;
            },
            [2] Adjustable {
                value = 200;
                defaultValue = 200;
                name = C;
                isDegrees = 0;
            },
            [3] Adjustable {
                value = 200;
                defaultValue = 200;
                name = E;
                isDegrees = 0;
            }
        );
        a = 0.6491648060943035;
        b = 0;
        c = 0;
        d = 0.6491648060943035;
        tx = -195.6666717529297;
        ty = -144.5;
        xOffset = -44.99840983089462;
        yOffset = 30.7939660691552;
        width = 650;
        height = 1000;
        centerX = 429.5;
        centerY = 499.9999999999999;
        calibrationSettings = CalibrationSettings {
            measurementUnitRaw = px;
            conversionRatio = 1;
            measuredLength = 0;
            startX = 0;
            startY = 0;
            endX = 0;
            endY = 0;
        };
        flapLocationRaw = ;
    };
    ohPlastyFlap = (null);
    curvelinearFlap = (null);
    rhomboidAFlap = RhomboidAFlap {
        id = 1;
        name = Rhomboid A;
        adjustables = List<Adjustable> <0x280b5c120> (
            [0] Adjustable {
                value = 60;
                defaultValue = 60;
                name = A;
                isDegrees = 1;
            },
            [1] Adjustable {
                value = 60;
                defaultValue = 60;
                name = B;
                isDegrees = 1;
            },
            [2] Adjustable {
                value = 200;
                defaultValue = 200;
                name = C;
                isDegrees = 0;
            },
            [3] Adjustable {
                value = 200;
                defaultValue = 200;
                name = E;
                isDegrees = 0;
            }
        );
        a = 0.6491648060943035;
        b = 0;
        c = 0;
        d = 0.6491648060943035;
        tx = -195.6666717529297;
        ty = -144.5;
        xOffset = -44.99840983089462;
        yOffset = 30.7939660691552;
        width = 650;
        height = 1000;
        centerX = 429.5;
        centerY = 499.9999999999999;
        calibrationSettings = CalibrationSettings {
            measurementUnitRaw = px;
            conversionRatio = 1;
            measuredLength = 0;
            startX = 0;
            startY = 0;
            endX = 0;
            endY = 0;
        };
        flapLocationRaw = ;
    };
    rhomboidBFlap = (null);
    noteFlap = (null);
    vyPlastyFlap = (null);
    bilobedFlap = (null);
    circularZFlap = (null);
    atPlastyFlap = (null);
    ouPlastyAFlap = (null);
    ouPlastyBFlap = (null);
    simpleEllipseFlap = (null);
}

这是病人的对象。

代码语言:javascript
复制
    Patient {
    id = 1;
    firstName = Gg;
    lastName = ;
    email = ;
    phone = ;
    address1 = ;
    address2 = ;
    city = ;
    state = ;
    dateOfBirth = 2019-04-03 21:24:28 +0000;
    medicalRedcordNumber = ;
    imageUrl = avatar_1;
    patientImages = List<PatientImage> <0x2834a5200> (
        [0] PatientImage {
            id = 1;
            hasPhoto = 1;
            isPostOp = 0;
            path = 4489901936;
            date = 2019-04-08 16:21:54 +0000;
            flap = (null);
            ohPlastyFlap = (null);
            curvelinearFlap = (null);
            rhomboidAFlap = (null);
            rhomboidBFlap = (null);
            noteFlap = (null);
            vyPlastyFlap = (null);
            bilobedFlap = (null);
            circularZFlap = (null);
            atPlastyFlap = (null);
            ouPlastyAFlap = (null);
            ouPlastyBFlap = (null);
            simpleEllipseFlap = (null);
        }
}

有人能帮我解决这个问题吗?在更新iOS版本和领域版本之前,不会发生此问题。

谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-04-29 05:03:06

这是因为每个瓣类(如ohPlastyFlap,curvelinearFlap .)覆盖皮瓣类和领域不识别皮瓣类型。

我通过正确设置皮瓣类型来修复它。

票数 1
EN

Stack Overflow用户

发布于 2019-04-26 11:16:08

您需要在这样的写事务中操作领域:

代码语言:javascript
复制
do {
    try self.realm.write
        {
        self.realm.add(entity, update: update)
         }
    }
catch {}
票数 2
EN

Stack Overflow用户

发布于 2019-05-05 01:57:51

"patient“对象缺少相应的初始化,该初始化仍然是零。

在此之前

代码语言:javascript
复制
patient.patientImages.append(newPatientImage)

试着为“耐心”创作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55866281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档