Blake Morgan
Blake Morgan

Reputation: 775

Unable to Subtract CGFloats

I'm trying to incorporate code from the Keyboard Management documentation produced by Apple into my app. So far I have been able to parse the Objective-C into Swift, but there is one line that I'm having problems with. Here it is in context (the last line is where the error occurs):

func keyboardWasShown(aNotification: NSNotification) {
    let info = aNotification.userInfo as NSDictionary!
    let kbSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue()

    let contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize!.height, 0.0)
    scrollView.contentInset = contentInsets
    scrollView.scrollIndicatorInsets = contentInsets

    let aRect = view.frame
    aRect.size.height -= kbSize!.height //This line gives me trouble.
}

At that line, I get an error message that says "Cannot invoke '-=' with an argument list of type '(CGFloat, CGFloat)'". Are there any work arounds to solve this problem or is there anything I'm doing wrong?


NB: I have tried casting them both to floats, but get the error "Cannot invoke 'init' with an argument list of type '($T4, $T9)'". When I cast the as floats in different variables and then subtract them, I get the error "Cannot invoke '-=' with an argument list of type '(Float, Float)'".

Upvotes: 0

Views: 1051

Answers (1)

gabbler
gabbler

Reputation: 13766

Please change let aRect to var aRect, a variable can be changed.

Upvotes: 2

Related Questions