<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This will fail to compile; it’s a bit <i class="">too</i> close to Java to work. In particular, in Swift you can’t pass a class into a function like invokeLater does; instead, Swift uses closures, which Java lacks and must make up with anonymous classes.<div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha</div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Jan 20, 2017, at 4:16 PM, Ethin Probst via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Is the following code valid swift 3 (and later) code? If not, is it<br class="">translatable to swift 3? This was translated using Elements Oxidizer<br class="">(<a href="http://elementscompiler.com/elements/oxidizer.aspx" class="">http://elementscompiler.com/elements/oxidizer.aspx</a>) using the Hello<br class="">World Java Swing application<br class="">(<a href="https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java" class="">https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java</a><br class="">and <a href="https://docs.oracle.com/javase/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java" class="">https://docs.oracle.com/javase/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java</a>).<br class="">It will run in RemObjects Silver in Visual Studio, but is it valid<br class="">Swift 3 code? You don't have to try and compile it--as Elements is the<br class="">only platform that compiles Swift to the JVM (I think?) but does it<br class="">follow the Swift 3 language specification (or the latest version,<br class="">whatever that may be)?<br class="">Code:<br class="">[start code]<br class="">import javax.swing<br class=""><br class="">public class HelloWorldSwing {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>private static func createAndShowGUI() {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>//Create and set up the window.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>var frame: JFrame! = JFrame("HelloWorldSwing")<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>//Add the ubiquitous "Hello World" label.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>var label: JLabel! = JLabel("Hello World")<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>frame.getContentPane().add(label)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>//Display the window.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>frame.pack()<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>frame.setVisible(true)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>public static func main(_ args: String![]) {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>//Schedule a job for the event-dispatching thread:<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>//creating and showing this application's GUI.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>javax.swing.SwingUtilities.invokeLater(class Runnable {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>func run() {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>createAndShowGUI()<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>})<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class="">}<br class="">[end code]<br class="">-- <br class="">Signed,<br class="">Ethin D. Probst<br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></div></body></html>