From 468af209eb481a42568a47cbdf41364fa8490c88 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Mon, 30 Oct 2023 19:09:50 +0100 Subject: [PATCH] placeholder --- Sources/CommonAppleKit/CommonAppleKit.swift | 20 ++++++++++++++++++- .../CommonAppleKitTests.swift | 8 ++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Sources/CommonAppleKit/CommonAppleKit.swift b/Sources/CommonAppleKit/CommonAppleKit.swift index 709c1ce..09a9a55 100644 --- a/Sources/CommonAppleKit/CommonAppleKit.swift +++ b/Sources/CommonAppleKit/CommonAppleKit.swift @@ -33,7 +33,13 @@ public extension CATextField { var stringValue: String { - text ?? "" + get { + text ?? "" + } + + set { + text = newValue + } } } @@ -87,6 +93,18 @@ public typealias CAWindow = NSWindow public typealias CARect = NSRect + public extension CATextField { + var placeholder: String { + set { + placeholderString = newValue + } + + get { + placeholderString ?? "" + } + } + } + public extension CAImage { @available(macOS 11.0, *) convenience init?(systemName: String) { diff --git a/Tests/CommonAppleKitTests/CommonAppleKitTests.swift b/Tests/CommonAppleKitTests/CommonAppleKitTests.swift index bf07647..e709aef 100644 --- a/Tests/CommonAppleKitTests/CommonAppleKitTests.swift +++ b/Tests/CommonAppleKitTests/CommonAppleKitTests.swift @@ -35,6 +35,14 @@ private final class ViewA: CAView { } final class CommonAppleKitTests: XCTestCase { + func testTextField() { + let textField = CATextField() + textField.stringValue = "Hello" + textField.placeholder = "world" + XCTAssertEqual(textField.stringValue, "Hello") + XCTAssertEqual(textField.placeholder, "world") + } + func testButton() { let button = CAButton() let selector = #selector(Self.onButtonTap)