Run Swift

// Declare our error type enum MyError: ErrorType { case NumberIsLower case NumberIsGreater } // Declare a function // that throws an exception func testFunc(a: Int) throws { if a<10 { throw MyError.NumberIsLower } else if a>10 { throw MyError.NumberIsGreater } else { print("Great!") } } // Try calling it // and catch all possible exceptions do { try testFunc(5) } catch MyError.NumberIsLower { print("Ooops! Number was lower than 10") } catch MyError.NumberIsGreater { print("Ooops! Number was greater than 10") }

  

Check Out Our New iSwift Lead Generation Software Bundle

Start your free demo


Foundation framework not available
Swift version 4.0.3
@ Ubuntu 16.04
 

Run Swift is a web tool where you can easily try Apple's Swift language online. Just paste any snippet and click    Run . You may also    Save  your scripts and/or share with the world. If what you're looking for is an easy-to-use tool for your Mac, to quickly test and run Swift code, then you may want to have a look at our Run Swift app for MacOS.