<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>
</head>
<body style="font-family:Arial;font-size:14px">
<p><strong>PROPOSING: Update WatchKit API Design to use properties instead of methods to set properties</strong></p>
<p>by Michie - https://github.com/michieriffic</p>
<p><br>
<strong>Introduction</strong><br>
<br>
WKInterfaceLabel is still using methods for set Text (setText), set Text Color (setTextColor), set Attributed Text (setAttributedText) to set properties of WKInterfaceLabel. I think it's more appropriate to make these into properties rather than methods just like in the UILabel. That would make it more consistent with building apps for both iOS, MacOS, WatchOS, and more.<br>
<br>
Also, other objects in WatchKit needs to be updated too to use properties instead of methods to set properties so we can easily access it using dot notation. WKInterfaceLabel is just an example.<br>
<br>
<strong>Motivation</strong><br>
<br>
While creating an app for watchOS, it has been a habit for me to use the dot notation to access a property of an object and set it using "=". And text, textColor, and attributedText are properties rather than methods of an object.<br>
<br>
<strong>Proposed solution &amp; detailed design</strong><br>
<br>
public class WKInterfaceLabel : WKInterfaceObject {<br>
<br>
&nbsp; &nbsp;public var text: String?<br>
&nbsp; &nbsp;public var textColor: UIColor?<br>
&nbsp; &nbsp;@NSCopying public var attributedText: AttributedString?<br>
<br>
}<br>
<br>
<em>INSTEAD OF</em><br>
<br>
public class WKInterfaceLabel : WKInterfaceObject {<br>
<br>
&nbsp; &nbsp;public func setText(_ text: String?)<br>
&nbsp; &nbsp;public func setTextColor(_ color: UIColor?)<br>
&nbsp; &nbsp;public func setAttributedText(_ attributtedText: AttributedString?)<br>
<br>
}<br>
<br>
<strong>Impact on existing code</strong><br>
<br>
Impact: <em>Would be more consistent and natural to the Swift language when building apps for WatchOS</em><br>
<br>
<strong>Before:</strong><br>
<br>
&nbsp; watchLabel.setText("Text String")<br>
&nbsp; watchLabel.setTextColor(UIColor.red())</p>
<p><strong>After:</strong><br>
<br>
&nbsp; watchLabel.text = "Text String"<br>
&nbsp; watchLabel.textColor = UIColor.red()</p>
<p>Will some Swift applications stop compiling due to this change? <em>Possible</em><br>
<br>
Will applications still compile but produce different behavior than they used to? <em>No, if everything was migrated properly.</em><br>
<br>
Is it possible to migrate existing Swift code to use a new feature or API automatically? <em>Yes.</em><br>
<br>
<strong>Alternatives considered</strong><br>
<br>
Just use what's currently available.</p>
</body>
</html>