Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 为什么强制展开会给我一个EXC_断点(SIGTRAP)错误?_Swift_Swift3 - Fatal编程技术网

Swift 为什么强制展开会给我一个EXC_断点(SIGTRAP)错误?

Swift 为什么强制展开会给我一个EXC_断点(SIGTRAP)错误?,swift,swift3,Swift,Swift3,我的应用程序在event.attenders中为参与者声明我的for循环时崩溃。我对swift比较陌生,我知道如果我检查Attendes数组是否为零,那么我可以自由地强制展开它。我在这里误解了什么 private static func parseParticipants(event: EKEvent) -> [Attendee] { var participants = [Attendee]() if(event.attendees != nil &&a

我的应用程序在event.attenders中为参与者声明我的for循环
时崩溃。我对swift比较陌生,我知道如果我检查Attendes数组是否为零,那么我可以自由地强制展开它。我在这里误解了什么

    private static func parseParticipants(event: EKEvent) -> [Attendee] {
    var participants = [Attendee]()

    if(event.attendees != nil && event.attendees?.count != 0) {
        for participant in event.attendees! {
            let participantName = parseEKParticipantName(participant)

            let isRequiredParticipant = participant.participantRole == EKParticipantRole.Required
            let hasAccepted = participant.participantStatus == EKParticipantStatus.Accepted
            let attendee = Attendee(name: participantName, email: participant.URL.resourceSpecifier!.lowercaseString, required: isRequiredParticipant, hasAccepted: hasAccepted)
            participants.append(attendee)
        }
    }
    return participants
}

使用可选绑定怎么样

if let attendees = event.attendees && attendees.count > 0 {

}

原来这不是强制展开,而是由于
EKParticipant.url
属性在包含
字符的字符串时返回nil

let attendee=attendee(姓名:participantName,电子邮件:participant.URL.resourceSpecifier!。小写,必填项:isRequiredParticipant,hasAccepted:hasAccepted)

我们使用它来访问参与者电子邮件,但是对
url
的任何读写操作都会导致崩溃,因此我们使用
EKParticipant.description
属性并使用正则表达式解析电子邮件


let participantEmail=participant.description.parse(模式:emailRegex).first??”“

我在操场上试过这个简单的例子,效果很好。您能提供更多详细信息吗?@ArG我也可以,但我的一些用户正在向这行代码发送崩溃报告。到目前为止,我无法复制错误。我尝试了一下,但不幸的是没有成功。这正是苹果SIGTRAP描述的主要原因,所以我很惊讶它没有。