Chatter application send function problem

Hello

I am making the Chatter application.
I have a problem with this send function in the ChatWindowController.swift

// MARK: - Actions
@IBAction func send(sender: AnyObject) {
sender.window?.endEditingFor(nil)
if let message = message {
let userInfo = [ChatWindowControllerMessageKey : message]
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.postNotificationName(ChatWindowControllerDidSendMessageNotification,
object: self,
userInfo: userInfo)
}
message = “”
}

The problem is the line: sender.window?.endEditingFor(nil)

I get error saying "Function value was used as a property; add () to call it

But when I do that it makes another error saying: " ‘window()’ is unavailable: APIs deprecated as of OS X 10.9 and earlier are unavailable in swift"

If I remove the line entirely it does not work either.
Did somebody have similar problems ?
Thank you for your time

Which versions of Xcode and Swift are you using? If you have upgraded to Xcode 7 & Swift 2.0 have you looked at the conversion guide? http://forums.bignerdranch.com/viewtopic.php?f=512&t=10109 I suspect this is the problem as I am seeing the same error now when I open my copy of the program which worked prior to the Xcode 7 update.

For future reference, when posting code, click the Code button above then paste your code in between the two tags. That will allow the browser to display it with the correct formatting.

[quote=“BrianLawson”]Which versions of Xcode and Swift are you using? If you have upgraded to Xcode 7 & Swift 2.0 have you looked at the conversion guide? http://forums.bignerdranch.com/viewtopic.php?f=512&t=10109 I suspect this is the problem as I am seeing the same error now when I open my copy of the program which worked prior to the Xcode 7 update.

For future reference, when posting code, click the Code button above then paste your code in between the two tags. That will allow the browser to display it with the correct formatting.[/quote]

Hello

Yes this is the solution. Thank you very much for help. I dont know how I missed that. It also explain why I had little difficulties while doing the exercises in the book, so far I managed to get around them, but now it is clear.
And thanks for the advice on posting code I will use it next time

Yes, I received the same error and do agree that it is likely due to the Xcode 7 / Swift 2 changes. I’m still not entirely sure of the cause, but my fix was to forcibly cast the sender as an NSView so that we can definitely get to the window property of that class. I don’t think the forced cast will be a problem as all of the UI controls inherit from NSView via NSControl. There may be a better way, but it worked for me.

@IBAction func send(sender: AnyObject) { let view = sender as! NSView view.window?.endEditingFor(nil) if let message = message { ...
EDIT: Actually… this is even easier, but it took me a few minutes to realize:“Hey, wait a minute, we’re always talking about the same window”…

@IBAction func send(sender: AnyObject) { self.window?.endEditingFor(nil) if let message = message { ...