by Ossi Hanhinen, @ohanhi
with the support of Futurice 💚.
Licensed under CC BY 4.0.
import Foundation | |
import Cocoa | |
import XCPlayground | |
public let DropNotification = "DropNotification" | |
public class DropWindow : NSWindow { | |
required public init?(coder: NSCoder) { | |
super.init(coder: coder) | |
self.registerForDraggedTypes([NSFilenamesPboardType]) |
When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.
So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.
Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?
I'm going to cover three things in this post:
/* | |
Erica Sadun, http://ericasadun.com | |
GameplayKit Available 10.11, iOS 9 | |
*/ | |
import Foundation | |
import GameplayKit // only available on OS X 10.11, iOS 9 |
Let's solve the following physics problem using Symbolism, a computer algebra library for C#.
One strategy in a snowball fight is to throw a first snowball at a high angle over level ground. While your opponent is watching the first one, you throw a second one at a low angle and timed to arrive at your opponent before or at the same time as the first one.
Assume both snowballs are thrown with a speed of 25.0 m/s.
The first one is thrown at an angle of 70.0° with respect to the horizontal.
import Cocoa | |
enum CoroutineState { | |
case Fresh, Running, Blocked, Canceled, Done | |
} | |
struct CoroutineCancellation: ErrorType {} | |
class CoroutineImpl<InputType, YieldType> { | |
let body: (yield: YieldType throws -> InputType) throws -> Void |
Visual Studio 2015 Update 1 was released today.
As part of this this release, a C# Interactive tool is provided. This is a read-eval-print loop for C#. It can be opened via the 'View -> Other Windows' menu:
Below is a screenshot demonstrating the computer algebra library Symbolism in C# Interactive:
import Cocoa | |
class MyAppDelegate: NSObject, NSApplicationDelegate { | |
let window = NSWindow() | |
var didFinishLaunching: NSWindow -> () = { _ in () } | |
func applicationDidFinishLaunching(aNotification: NSNotification) { | |
didFinishLaunching(window) | |
} | |
} |