Tag: swift

Parsing sentences from a String in Swift

I’ve been looking at how to parse sentences from text recently. While I’m still looking for a more Machine Learning approach, I found NSStringEnumerationBySentences which can get me there faster (for now).  I need to get all of the sentences from a given String.  This could easily be an Objective-C category method.  But, I’m trying to learn as much Swift as I can. I haven’t played with extensions yet. Here we go. is what I’ll need, but I need the extension first: Fiddling with Swift’s closure syntax for a…

Playgrounds in Swift are Awesome

Man alive, I missed this from Python.  More live editing, less edit+build+run. 2014-07-12_1822

Functions or Read-Only Properties in Swift?

I’m not sure which is better.  If it's returning something that is directly tied to the class: a slice/dice of properties is already has, I'm leaning towards properties. Because of the many examples I feel like read-only properties are the way to do.  I’m not the only person [wondering](http://stackoverflow.com/questions/24035276/computed-read-only- property-vs-function-in-swift), so that’s validating. Property: Function:

Looping through subviews and downcasting in Swift

I've been playing around with Auto-Layout. This snippet was helpful to see what constraints were set on what views in my View Hierarchy. Getting the downcast right on the subviews Array took a few tries:

Creating a conforming delegate (UITableViewDelegate) in Swift

This tripped me up for a bit so I hope this helps someone. I started out with this class, thinking I could just continue on my merry way. This errors in Xcode with: "class does not conform to NSObjectProtocol” Hmm ok, but much there yet, what did I miss? This should definitely be a class; not a protocol (I have methods to implement), not a @class_protocol (wrong use, based on the docs), hmm. This obviously behaves different than in objective-c. What is inherent in the obj-c version of this that would…

Using PonyDebugger on a device

PonyDebugger is awesome. I use it mostly for Core Data debugging. Most of the time, I find it easier then firing up SQLite Professional. When using the simulator, hitting localhost:9000 is fine. On a device, not so much; you need to hit your machine. xip.ioto the rescue! What it is: xip.io is a magic domain name that provides wildcard DNS for any IP address. We use this heavily at work if the machine we’re on isn’t hooked up to a subdomain or [Vagrant Share](https://www.vagrantup.com/blog/feature- preview…

Dismiss a Modal UIViewController created in Interface Builder

There are a number of posts on this subject on Stack. They involve re-instantiating (this seems slower to me) or yanking the view from a UIButton (this feels dirty). I’d rather just update the UIBarButtonItem that I already have: 2014-07-27_1826 All I needed to do, was attach the appropriate target and action to the UIBarButtonItem:

UITableViewCell Action Swiping in iOS8 and Swift

Mail.app in iOS7 brought swiping cells to the inbox. The iOS8 beta added a 3rd button to it.  Apple has also introduced an API to assist with creating this effect: UITableViewRowAction. Prior to this, I used SWTableViewCell. Below is how to get the basic functionality working. Please note that you have to implement the 2nd function whether it has a body or not I can’t get the (-) delete indicator to appear when I put the table into edit mode though. Setting UITableViewCell.shouldIndentWhileEditing = NO is…

Testing UIViewController Transitions with Quick and Swift

The examples below are using the Quick test framework, but the principals we're going to talk about can be used in any setup. We have some complicated logic further down our user registration flow. I want to make sure that the right UIViewControllers are appearing when they are supposed to. I've been reading a few different approaches on how to handle this. Below is where I've ended up, and I'm pretty happy with it. For simplicity's sake, I'm going to show how to test if the user has tapped "Login" or…

Using an Encrypted Realm in a background or notification processes?

Note: This post's primary purpose is to help me think through this problem. I have no prescribed solution at the end of it. The conversation will continue on Stack Overflow. I will update this post once I have a final approach. Realm has a great write up and sample code for encrypting your database. This documentation and sample work as intended, until you try to decrypt realm when: A user has a password on their phone The device is locked Your app is trying to do work with Realm when a remote notification…