Yellow Warnings: Conditional picking from UITextDocumentProxy to UIKeyInput always succeeds

I am working on keyboard, I just installed xcode 7 beta 2 and then I get a lot of warnings.

More than 24 yellow errors, I think this is causing the keyboard to crash on xcode 6.4 No errors and no keyboard Course

I find it difficult to resolve errors.

Warnings:

Conditional fetch from UITextDocumentProxy to UIKeyInput is always executed

func handleBtnPress(sender: UIButton) {
    if let kbd = self.keyboard {
        if let textDocumentProxy = kbd.textDocumentProxy as? UIKeyInput {
            textDocumentProxy.insertText(sender.titleLabel!.text!)
        }

        kbd.hideLongPress()

        if kbd.shiftState == ShiftState.Enabled {
            kbd.shiftState = ShiftState.Disabled
        }

        kbd.setCapsIfNeeded()
    }
}

      

Warnings:

Conditional selection from UITouch to UITouch is always done

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for obj in touches {
        if let touch = obj as? UITouch {
            let view = self.touchToView[touch]

            let touchPosition = touch.locationInView(self)

            if self.bounds.contains(touchPosition) {
                self.handleControl(view, controlEvent: .TouchUpInside)
            }
            else {
                self.handleControl(view, controlEvent: .TouchCancel)
            }

            self.touchToView[touch] = nil
        }
    }
}

      

+3


source to share


1 answer


These are not errors, they are just warnings, and they are probably not the cause of your crashes, however you can solve these two examples by following these steps:

The protocol UITextDocumentProxy

is compliant anyway UIKeyInput

, so there is no need to use kbd.textDocumentProxy

both UIKeyInput

.

You can do the following without any warnings:

func handleBtnPress(sender: UIButton) {
    if let kbd = self.keyboard {
        kbd.textDocumentProxy.insertText(sender.titleLabel!.text!)
        kbd.hideLongPress()

        if kbd.shiftState == ShiftState.Enabled {
            kbd.shiftState = ShiftState.Disabled
        }

        kbd.setCapsIfNeeded()
    }
}

      

The same with obj

, the compiler already knows that it is an object UITouch

, so there is no need to throw it, you can output all the code from the statement if let touch = obj as? UITouch

like this:



override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        let view = self.touchToView[touch]

        let touchPosition = touch.locationInView(self)

        if self.bounds.contains(touchPosition) {
            self.handleControl(view, controlEvent: .TouchUpInside)
        }
        else {
            self.handleControl(view, controlEvent: .TouchCancel)
        }

        self.touchToView[touch] = nil
    }
}

      


Little tip: altclick on a variable to see what type was resolved like:

enter image description here

+2


source







All Articles