首页 > 解决方案 > 分段错误 11 仅适用于 xcode 10 swift 3

问题描述

我将 xcode 9.4 与 swift 3 一起使用,代码运行良好,并且已上线。现在,当我在 xcode 10.1 中运行相同的代码时,我收到很多segmentation fault 11文件的错误。不知道我该怎么做。我怎样才能将我的 swift 3 转换为 swift 4。因为很多文件我需要更改语法。

更好的是我需要在 xcode 10.1 中使用 swift 3 并且需要解决这个问题segmentation fault 11

我在这里遇到的主要错误:

  1. 在 /Users/Documents/Rough/jeder/JEDE_r/AppDelegate.swift:258:5 处为“application(_:didReceiveRemoteNotification:)”发出 SIL 时
  2. 而 silgen emitFunction SIL 函数“@$S3WCi11AppDelegateC11application_28didReceiveRemoteNotificationySo13UIApplicationC_SDys11AnyHashableVypGtF”。对于 /Users/Documents/Rough/jeder/JEDE_r/AppDelegate.swift:258:5 处的“应用程序(_:didReceiveRemoteNotification :)”错误:分段错误:11

我的代码:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) 
{
    if application.applicationState == .inactive || application.applicationState == .background {
        //opened from a push notification when the app was on background
    }
    else
    {
        if application.applicationState == .active
        {
            let myuserinfo = userInfo as NSDictionary
            print(myuserinfo)

            let tempDict:NSDictionary = (myuserinfo.value(forKey: "aps") as? NSDictionary)!
            let alert = UIAlertView(title: "alertView", message: (tempDict.value(forKey: "alert") as? String)!, delegate: nil, cancelButtonTitle:"Cancel", otherButtonTitles: "Done", "Delete")
            alert.show()
            let person:NSDictionary = (tempDict.value(forKey: "custom") as? NSDictionary!)!
        }
    }
}

这里有什么问题。我怎样才能解决所有segmentation fault 11显示该错误的近 22 个文件的错误。

请对此有任何帮助!

标签: iosswiftiphoneswift3xcode10

解决方案


更改此行:

let person:NSDictionary = (tempDict.value(forKey: "custom") as? NSDictionary!)!

let person:NSDictionary = (tempDict.value(forKey: "custom") as? NSDictionary)!

同样在同一个 appdelegate 中,你也做同样的另一种方法。将该行替换为上述行。可能是这个帮助。如果您有任何问题,请告诉我或发布任何其他问题。


推荐阅读