Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.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
Ios Xcode 7错误与.toInt、iPhone LED和邮件生成器_Ios_Xcode_Swift_Swift2_Xcode7 - Fatal编程技术网

Ios Xcode 7错误与.toInt、iPhone LED和邮件生成器

Ios Xcode 7错误与.toInt、iPhone LED和邮件生成器,ios,xcode,swift,swift2,xcode7,Ios,Xcode,Swift,Swift2,Xcode7,我刚刚下载了Xcode 7并通过1.0到2.0 migrator运行了我的应用程序,收到了五个错误,两个是计算器错误,两个是iPhone LED切换错误,还有一个是我应用程序中的mail composer错误 对于caluclator, 我收到了.toInt的错误,说“toInt不可用,请使用Int()初始值设定项。我用破折号标记了行 @IBAction func launchEmail(sender: AnyObject) { @IBOutlet weak var Screen: UILab

我刚刚下载了Xcode 7并通过1.0到2.0 migrator运行了我的应用程序,收到了五个错误,两个是计算器错误,两个是iPhone LED切换错误,还有一个是我应用程序中的mail composer错误

对于caluclator, 我收到了.toInt的错误,说“toInt不可用,请使用Int()初始值设定项。我用破折号标记了行

@IBAction func launchEmail(sender: AnyObject) {

@IBOutlet weak var Screen: UILabel!
var firstNumber = Int()
var secondNumber = Int()
var isTypingNumber = false
var result = Int()
var operation = ""


@IBAction func number(sender: AnyObject) {
    let number = sender.currentTitle
    if isTypingNumber == true {
        Screen.text = Screen.text! + number!!
    } else {
        Screen.text = number;
    }
    isTypingNumber = true
}


@IBAction func operation(sender: AnyObject) {
    isTypingNumber = false
    ---- firstNumber = Screen.text!.toInt()!----------
    operation = sender.currentTitle!!
}


@IBAction func equals(sender: AnyObject) {
    ---- secondNumber = Screen.text!.toInt()! ----------
    if operation == "+" {
        result = firstNumber + secondNumber
    } else if operation == "-" {
        result = firstNumber - secondNumber
    } else if operation == "X" {
        result = firstNumber * secondNumber
    } else {
        result = firstNumber / secondNumber
    }
    Screen.text = "\(result)"
}


@IBAction func clear(sender: AnyObject) {
    firstNumber = 0
    secondNumber = 0
    isTypingNumber = false
    result = 0
    Screen.text = "\(result)"
}
对于手机LED, 我有两个错误,一个是(在第一行中有破折号)说,“不能调用参数类型为(nil)的'LockForConfiguration'。第二行(虚线)上写着“调用中的额外参数‘错误’”

邮件编写器的最后一个例子, 在虚线上,我得到一个错误,上面说“'MFMailComposer Result'没有名为'value'的成员。” @iAction func启动邮件(发件人:AnyObject){

我应该改变什么样的东西才能让它们工作呢。
非常感谢您的帮助。非常感谢:):)

对于第一个错误,您必须使用
Int
的初始值设定项(可失败),而不是
.toInt()
,如下所示:

firstNumber = Int(Screen.text!)!
第二个错误来自Swift 2中的新错误处理模型,其中许多函数现在使用
inout
参数
thows
处理错误:

如果您确定没有引发错误(如果是,则引发运行时错误),请使用:

如果可以抛出错误,但希望忽略它并继续执行(如现在):

如果要在抛出任何错误后直接返回:

do {
    try device.lockForConfiguration()

    if (device.torchMode == AVCaptureTorchMode.On) {
        device.torchMode = AVCaptureTorchMode.Off
    } else {
        try device.setTorchModeOnWithLevel(1.0)
    }
    device.unlockForConfiguration()
} catch {
    // here you can use an automatically created "error" variable
    // notice that "error" can be from both functions
    return
}

不幸的是,我不知道第三个错误的修复方法。

更改的整数转换和更改的错误处理(使用异常)记录在Xcode 7 beta发行说明中。您的第一个问题是的副本。(编译器消息“toInt不可用,请使用Int()初始值设定项。”足够谷歌解决吗?–一般来说,你的问题太宽泛了,因为它包含3个不同的问题。你忘记了上一个例子中的虚线。为了表示感谢,你应该接受Qbyte的答案。
firstNumber = Int(Screen.text!)!
try! device.lockForConfiguration()
try! device.setTorchModeOnWithLevel(1.0)
do {
    try device.lockForConfiguration()
} catch {}

if (device.torchMode == AVCaptureTorchMode.On) {
    device.torchMode = AVCaptureTorchMode.Off
} else {
    do {
        try device.setTorchModeOnWithLevel(1.0)
    } catch {}
}
device.unlockForConfiguration()
do {
    try device.lockForConfiguration()

    if (device.torchMode == AVCaptureTorchMode.On) {
        device.torchMode = AVCaptureTorchMode.Off
    } else {
        try device.setTorchModeOnWithLevel(1.0)
    }
    device.unlockForConfiguration()
} catch {
    // here you can use an automatically created "error" variable
    // notice that "error" can be from both functions
    return
}