gpt4 book ai didi

ios - 线程 1 : Breakpoint 4. 1 - swift

转载 作者:行者123 更新时间:2023-11-28 07:12:05 24 4
gpt4 key购买 nike

<分区>

每当我使用“println(buildDateString("xx","xx","xx","xx","xx")"调用我的 buildDateString 方法时,我的应用程序崩溃,给我错误消息“线程 1:断点 4.1 "

import Foundation
import UIKit

func getDateFromString(dateString: String) -> NSDate? {
var dateFormatter: NSDateFormatter = NSDateFormatter()

dateFormatter.dateFormat = "MM-dd-yyyy-kk-mm-ss"
dateFormatter.timeZone = NSTimeZone.localTimeZone()

return dateFormatter.dateFromString(dateString)
}

func getCurrentDateAsArray() -> [Int] {
var dateFormatter: NSDateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy-kk-mm-ss"
dateFormatter.timeZone = NSTimeZone.localTimeZone()

var dateString = dateFormatter.stringFromDate(NSDate())

return stringToIntArray(dateString.componentsSeparatedByString("-"))
}

func stringToIntArray(stringArray: [String]) -> [Int] {
var intArray: [Int] = []

for element in stringArray {
intArray.append(element.toInt()!)
}

return intArray
}

func intToStringArray(intArray: [Int]) -> [String] {
var stringArray: [String] = []

for element in intArray {
stringArray.append("\(element)")
}

return stringArray
}

func buildDateString(day: String, month: String, hour: String, minute: String, second: String) -> String {
var dayValue = day
var monthValue = month
var hourValue = hour
var minuteValue = minute
var secondValue = second
var currentDate = getCurrentDateAsArray()

println(currentDate)

dayValue = dayValue.utf16Count == 1 ? "0" + dayValue : dayValue
monthValue = monthValue.utf16Count == 1 ? "0" + monthValue : monthValue
hourValue = hourValue.utf16Count == 1 ? "0" + hourValue : hourValue
minuteValue = minuteValue.utf16Count == 1 ? "0" + minuteValue : minuteValue
secondValue = secondValue.utf16Count == 1 ? "0" + secondValue : secondValue

var bool1 = monthValue.toInt() > currentDate[0]
var bool2 = monthValue.toInt() == currentDate[0] && dayValue.toInt() > currentDate[1]
var bool3 = monthValue.toInt() == currentDate[0] && dayValue.toInt() == currentDate[1] && hourValue.toInt() > currentDate[3]
var bool4 = monthValue.toInt() == currentDate[0] && dayValue.toInt() == currentDate[1] && hourValue.toInt() == currentDate[3] && minuteValue.toInt() > currentDate[4]
var bool5 = monthValue.toInt() == currentDate[0] && dayValue.toInt() == currentDate[1] && hourValue.toInt() == currentDate[3] && minuteValue.toInt() == currentDate[4] && secondValue.toInt() > currentDate[5]

if (bool1 || bool2 || bool3 || bool4 || bool5) {
currentDate[2] = currentDate[2] + 1
}

var currentDateStringArray: [String] = [monthValue, dayValue, "\(currentDate[2])", hourValue,minuteValue, secondValue]

return "-".join(currentDateStringArray)
}

我不明白为什么会这样,而且 xCode 也没有给我任何关于错误可能是什么的提示。

我正在使用带有 xCode 6.2 beta 4 的 iOS 8.2 SDK

错误被抛到这一行:

println(buildDateString("12", "5", "12", "12", "7"))

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com