I am getting EXC_BAD_ACCESS (code=1, address=0x30) Bad Access even when object exists - swift 4

风流意气都作罢 提交于 2020-01-06 07:26:14

问题


Similar to This SO Post and This SO Post

I initialize a variable ----> idHERE:

static func createPractitionerRole(fromRoleDict roleDict:[String: AnyObject])->PractitionerRole?{

    guard let (nameL, idL) = getRoleNameId(fromRoleDict:roleDict) else {
            return nil
    }

    let roleTypeL = ProTouchRoleType.determineRoleTypeFromProTouchId(idL)

    var idHERE =  Identifier(withValue: idL, systemParam:Constants.CodeSystem.ProTouch.coding_system_proTouchURL)

    print("idHERE \(String(describing:  idHERE))")

    print("idHERE.value \(String(describing:  idHERE.value))")

    return PractitionerRoleUtils.createPractitionerRole(withId:idHERE, name: nameL, roleType: roleTypeL)
}

On the first print it prints out the object:

idHERE Identifier Object- system:Optional(http://www.anyApp.com/any) value:Optional("319/43") use:usual period:nil

But on the second print when I try to use idHERE.value - I get a bad access EXC_BAD_ACCESS (code=1, address=0x30)

How is this possible?

The debugger shows all the values fine as well.

I have tried running the code in release mode with no help.

Please help!!

Xcode 9 swift4

Also, I changed this from a let to a var to see if that made a difference.

This after some complicated code, but I'm not sure why that would make a difference. Why, if you initialize something, can't you access the values immediately after.

Also, deinit is NOT called. I have a print statement for deinit and it is not called.

Thanks!


回答1:


My only work around as of now is changing the optimization level to -02 for both release and debug. Now it "works". Someone from swift needs to look at this!!

Links to Look at Later 1

Also had bad access and changed optimization level



来源:https://stackoverflow.com/questions/48795609/i-am-getting-exc-bad-access-code-1-address-0x30-bad-access-even-when-object-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!