で働く - Xcodeのエラーを示しています、私はアプリを持っていると私は、実際のデバイス上でこのアプリを実行しようとした場合(iPhone 5Sと6)シミュレータ
fatal error: unexpectedly found nil while unwrapping an Optional value 2017-04-11 00:43:58.724143+0200 APN[2153:475883] fatal error: unexpectedly found nil while unwrapping an Optional value
あり問題のあるコードブロック。しかし、シミュレータではすべて正常で正しいです。
let stringBefore = "Mon, 10 Apr 2017 11:39:24 +0000"
let startIndexDate = stringBefore.index(stringBefore.startIndex, offsetBy: 5)
let endIndexDate = stringBefore.index(stringBefore.endIndex, offsetBy: -15)
let rangeDate = startIndexDate..<endIndexDate
let stringAfter = stringBefore.substring(with: rangeDate)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd MMM yyyy"
let date = dateFormatter.date(from: stringAfter)
dateFormatter.dateFormat = "dd.MM.yyyy"
let finish = dateFormatter.string(from: date!) // there is the problem but why in Simulator is ok?
私は
dateFormat = "EEE, dd MMM yyyy hh:mm:ss +zzzz"
を書くことができることを知っているが、私は、問題がどこにあるかお聞きしたいですか?
'stringAfter'の値を表示し、その値が何であるかを確認してください。 'dd MMM yyyy'と一致してはいけません。 – rmaddy
英語の平日と月の名前を持つ固定フォーマットを使用しているので、12/24時間形式の問題を回避したいので、フォーマッタのロケールを 'en_US_POSIX'に設定する必要があります。 – rmaddy
ありがとう、それは働いている!!!! – spread7