All posts tagged: Swift

Reversing a Swift String in Place

Dev

One of the interview questions at my old job we’d ask sometimes was to reverse a string in place; usually using C or Java. After conducting an interview one time, I decided to rewrite it in Swift. Here’s what I came up with: func reverse(string: inout String) { var i = string.startIndex var j = string.index(before: string.endIndex) while i < j { let first = string[i] let second = string[j] string.remove(at: i) string.insert(second, at: i) […]

Equatable Swift (NS)Objects

Dev

How to implement equality with different kinds of Swift objects was pretty obvious once I read the documentation, but the errors I got at first were not entirely clear. If you want to show equality between two objects in Swift, you have to do something different depending on if they subclass NSObject or not. In the case of an NSObject subclass, you would override -isEqual:: override func isEqual(to object: Any?) -> Bool { guard let […]

Swift NSManagedObjectContext Extension to Delete All Core Data Objects

Dev

I made this NSManagedObjectContext extension so that I could delete all of a users data when they log out of the app I’m writing. The alternative was to delete the sqlite file itself and reinitialize my Core Data stack, but that seemed potentially more problematic and less safe. The two instance methods on NSManagedObjectContext for deleting objects are: func deleteAllObjects(error: NSErrorPointer) Delete all objects in a context. Bails out and returns an error if there’s […]

Trying Swift Again

Dev

On my most recent project, I decided to try going Swift from the start. I did the same thing when I started working on a rewrite of the Lovely app around the end of last summer, but found the tools too immature then. This time I’ve spent about a week with it, and everything seems is working out fine (so far). I’ve tried to keep up reading about the language itself, so the syntax hasn’t […]

Alamofire

Dev

Alamofire is a new networking library — written in Swift — from the creator of AFNetworking. So far I’ve just read the post on NSHipster about it, but I like what I see. It’s not a value judgment, but something AFNetworking has never quite sat right with me. This looks very lightweight and more like something written to be idiomatic Swift rather than Objective-C in Swift’s clothing.

Objective-C Without the Smalltalk

Dev

This is a really good post lamenting some of the direction Swift has chosen to take: Gone is the dynamic nature of ObjC; it has instead been replaced by a rigid, generic based type system. I know the world of C++, Java, and C# programmers have rejoiced. Myself, having worked in Visual Studio building tools for .NET and Windows developers for many years and leaving that for the world of Cocoa and ObjC, I am […]