2016-11-11 4 views
1

forループの宣言に私のアプリケーションがクラッシュしていますfor participant in event.attendees!。私は比較的迅速で、参加者配列が無制限でないことを確認すると、unwrapを強制することは自由です。私はここで何を誤解していますか?Force UnwrappingでEXC_BREAKPOINT(SIGTRAP)エラーが発生するのはなぜですか?

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 
} 
+1

私が遊び場で、この単純な例を試してみましたが、それが正常に動作します。 http://paste.ofcode.org/vc6q8kYyYq5Sk5HjqNSrAf 詳細をお知らせください。 – ArG

+0

@ArGそれは私にとっても同様ですが、私のユーザーの中には、このコード行に向けられたクラッシュレポートを送信している人がいます。私はこれまでのところエラーを再現することができませんでした。 – Deco

答えて

1

このアンラッピングについて力ではなかったが、それは"文字が含まれている文字列を含んでいたときにnilを返すEKParticipant.url性質によるものであったが判明。

let attendee = Attendee(name: participantName, email: participant.URL.resourceSpecifier!.lowercaseString, required: isRequiredParticipant, hasAccepted: hasAccepted)

我々は、参加者の電子メールにアクセスするために、これを使用しますがurlへの読み取りまたは書き込み操作は、私たちはEKParticipant.description財産を取り、正規表現を使用して電子メールを解析されたクラッシュを引き起こしました。

let participantEmail = participant.description.parse(pattern: emailRegex).first ?? ""

0

オプションのバインディングの使用はどうですか?

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

} 
+0

私はこれを行ったが、残念ながら働かなかった。 それは、リンゴのSIGTRAPの記述が主な原因としているものであり、そうではないと私は驚いています。 – Deco

関連する問題