-
Notifications
You must be signed in to change notification settings - Fork 872
/
Copy pathAddItemViewController.swift
33 lines (24 loc) · 1.16 KB
/
AddItemViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
The `AddItemViewController` class displays the user interface for creating a new list item in the table view.
*/
import Cocoa
// A protocol that allows a delegate of `AddItemViewController` to be aware of any new items that should be created.
@objc protocol AddItemViewControllerDelegate {
func addItemViewController(addItemViewController: AddItemViewController, didCreateNewItemWithText text: String)
}
class AddItemViewController: NSViewController {
// MARK: Properties
weak var delegate: AddItemViewControllerDelegate?
// MARK: IBActions
@IBAction func textChanged(textField: NSTextField) {
let cleansedString = textField.stringValue.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
if !cleansedString.isEmpty {
delegate?.addItemViewController(self, didCreateNewItemWithText: cleansedString)
}
// Tell the presenting view controller to dismiss the popover.
presentingViewController?.dismissViewController(self)
}
}