Category Archives: Swift

Swift Exceptions

Nick Lockwood has one of the best discussions of Swift exceptions I’ve found both in terms of design, problems and benefits.

Related Posts

  • 85
    “Silver” brings Apple’s Swift language to the .NET and Java worlds. It brings the language not the Cocoa libraries though. Sounds like they added exceptions to let Swift work with .NET or Java better. (Personally I think Apple should add exceptions too, but I know people at Apple really don’t like…
    Tags: exceptions, swift
  • 77
    There were some big changes to Swift this week. The most surprisingly controversial one was the adding of “exceptions.” I put those in quotes because they are quite unlike traditional exceptions in C++, C#, Java or Python even though I’ve called them Pythonesque at times.[1. I think I called them…
    Tags: exceptions, swift
  • 48
    Calling Swift from C.
    Tags: swift
  • 47
    Swift’s command line tools have changed somewhat. (HT: SwiftDevs)
    Tags: swift
  • 47
    Hashbanging Swift. Using Swift at the command line. I had enough issues trying to replace Python with Swift that I went back to Python.
    Tags: swift

Controversial Swift Exceptions

There were some big changes to Swift this week. The most surprisingly controversial one was the adding of “exceptions.” I put those in quotes because they are quite unlike traditional exceptions in C++, C#, Java or Python even though I’ve called them Pythonesque at times.1 Whoa. People on both sides of the debate flip out on that!

There have been two types of reactions.

First (the majority) is excitement. Finally we have something to avoid all those nested and hard to read if statements.

Second (a loud minority) are those groups that hate exceptions or think Swift did them wrong. From what I can tell one group are primarily those coming from ObjcC where exceptions were always warned against. (ObjC has long had C++ styled exceptions but few use them) There’s also the Haskell/Clojure folks who also hate exceptions. Both these groups shout the, “Swift isn’t learning from the mistakes of the past and is dominated by C++ folks.” The related group (sometimes also disliking exceptions in general but sometimes a fan of C++ or related exceptions) are those who note that Swift’s exceptions aren’t even really exceptions. 

Continue reading Controversial Swift Exceptions

  1. I think I called them Pythonesque because it’s fairly common in Python to use exceptions for error handling and not just unexpected catastrophic failures. To be fair not everyone agrees with that type of programming. Also unlike C++ Python’s exceptions are kind of intrinsically tied to an error state and the error state isn’t necessary catastrophic. The calling function is just supposed to respond to the error, fix things up a bit so you can continue and clear the error indicator. (See Python exceptions)

Related Posts

  • 77
    Nick Lockwood has one of the best discussions of Swift exceptions I’ve found both in terms of design, problems and benefits.
    Tags: swift, exceptions
  • 63
    “Silver” brings Apple’s Swift language to the .NET and Java worlds. It brings the language not the Cocoa libraries though. Sounds like they added exceptions to let Swift work with .NET or Java better. (Personally I think Apple should add exceptions too, but I know people at Apple really don’t like…
    Tags: exceptions, swift
  • 54
    Could have sworn I’d linked to this before. But I guess not. It’s well worth reading. Reactive Cocoa in Swift. The biggest issue right now is that Swift can’t see macros in ObjC/C. Given some of the problems that introduces I’ll hold off until things get more mature. The linked…
    Tags: swift, programming

Silver: Swift for .NET

“Silver” brings Apple’s Swift language to the .NET and Java worlds. It brings the language not the Cocoa libraries though. Sounds like they added exceptions to let Swift work with .NET or Java better. (Personally I think Apple should add exceptions too, but I know people at Apple really don’t like exceptions and use them just for a very limited set of errors)

Related Posts

  • 85
    Nick Lockwood has one of the best discussions of Swift exceptions I’ve found both in terms of design, problems and benefits.
    Tags: swift, exceptions
  • 63
    There were some big changes to Swift this week. The most surprisingly controversial one was the adding of “exceptions.” I put those in quotes because they are quite unlike traditional exceptions in C++, C#, Java or Python even though I’ve called them Pythonesque at times.[1. I think I called them…
    Tags: exceptions, swift
  • 44
    How to merge Apple Photos libraries. Unfortunately requires sufficient iCloud space.
    Tags: libraries, apple

Changing Formatting with Swift

Someone on Ars asked about Applescripting to highlight text in Mail. Now there actually are some easy ways to do this if you go into GUI scripting in Mail. However there are also some limits. I looked at the problem thinking I might just modify some old Python scripts. However I quickly realized nearly everything I was doing was Cocoa so I decided to do it in Swift instead.

Continue reading Changing Formatting with Swift

Swift with Cocoa Applescript

Using Swift with ApplescriptObjC and Cocoa-AppleScript.

Seems like a nice tutorial although I’ve not tried it yet. (Quite busy) I’d tried to get this same thing working during the summer and never did. Maybe I’ll give it an other whirl. It’s pretty close to what I tried. Effectively you’re mixing the old way to mix Applescript and ObjC together and throwing a little Swift in the mix.

I think Swift would be a fantastic replacement for Applescript if there was a simple non-convoluted way to run scripts. Something on par with Python + Appscript. (What I used to use for all my scripting)

I should note that I’ve tried using Apple’s Javascript replacement for Applescript. However I do a lot of GUI scripting in most of my scripts and for some reason Javascript didn’t like some of those GUI objects. 

Related Posts

  • 60
    I’d mentioned in passing in one of my Swift posts about using it as a scripting language. Someone on Twitter asked me if I’d convert from using Python to Swift for my scripts. It’s an excellent question that I really can’t answer fully at this stage. The language is still…
    Tags: swift, python, scripts, scripting
  • 41
    Nick Lockwood has one of the best discussions of Swift exceptions I’ve found both in terms of design, problems and benefits.
    Tags: swift, ve