Categories
Development iOS Work Note

Work Note: Loading View Controllers from a Storyboard

When I need to load a view controller from a Storyboard I like to create an extension to the view controller’s class and add a class function to it that does the work. It keeps things looking clean in the code where you use it.

I’m not sure if this is smart or dumb. I’m sure very smart people will let me know. Here’s an example.

Here’s how you’d use it in your code.

Categories
Development Work Note

Work Note: git flow feature start fails

This morning I was creating a new branch to start work on a new feature and I use git flow.

To start a new feature you type…

git flow feature start FeatureName

After typing that and pressing enter git flow complained that it was initialized and I should run the command…

git flow init

I’ve been working in this same environment for two years. I know git flow is configured, but like a good automaton I followed the directions. Of course, you can guess what happened, right? Yep, git flow init says “Hey, you’re good to go!”

I wasn’t. My commands still failed with the same message.

Luckily there is a fix.

Yep, that’s right, cd into the .git directory for that repository and remove all git flow references from your git config file. Then run git flow init. All better.

Categories
Development Swift Work Note

Work Note – Swift Thoughts

wrongSwiftLogoI’ve been working in Swift more and more over the past couple months. To get started I wrote a simple parsing class for Agrian, the product I work on. More recently, as in this week, we started doing most work in Swift. The syntax is super sugary and will take some getting used to, but I can already see I’m going to love working in it.

It seems if you have a background in C, C++, or C#, you should feel right at home. I wonder how JavaScript developers feel about it? If you have an opinion feel free to leave a comment, or write about it on your weblog. I’m curious what you have to say.

This afternoon as I was working on the app I found myself wishing I could do something like this with Swift.

let textView = UITextView() {
    .userInteractionEnabled = false
    .font = .defaultFont(14)
    .backgroundColor = .yellowColor()
}

It feels like a natural thing to do, I don’t know why, but it does. We’re working in Swift 2.0, so if there is a way to do this, please let me know, I don’t think we can, but I’m such a noob, I’m not sure about much.

Categories
Development Objective-C Work Note

Work Note: Conditional Breakpoints in Xcode

If you’ve been developing for any period of time you’ll understand that the debugger is your friend. This tip is probably not new to a lot of folks, but I thought I’d share for anyone new to Xcode, Cocoa, and Objective-C development.

The Conditional Breakpoint

We’ve all set breakpoints in Xcode while debugging, but did you know you can set conditional breakpoints? Let’s say you’re processing a large quantity of data and you say to yourself “Man, I wish I could break right here when the value of this string is ‘labs'” Guess what, you can. Two easy steps

Step #1: Right click (Command-Click) on the breakpoint and select Edit Breakpoint…

Edit Breakpoint in Xcode

Step #2: In the popover type “(BOOL)[documentName isEqualToString:@”labs”]” into the Condition field.

Xcode Breakpoint Condition
That’s all you need to do! In this case the breakpoint will be skipped until documentName is “labs.”

Categories
Development Objective-C Work Note

Work Note: That compiled?

I just ran across something that had me stumped for a while, I just couldn’t see it, and I would have thought the compiler would have choked on it. It didn’t, it built, and ran, and produced interesting results.

Confession time: I’m not using auto layout, yet. Why? I haven’t had the time to commit to it. Yes, I’m aware it would probably save me time in the long run. I will learn it, of course, just not today.

Anywho, back to the story.

I hade some code that looked like this, I must have been distracted mid-thought, and did a build. This code built.

self.thingView.frame = frame;
self.thingView.frame

AHHHHHH!Anyone see a problem there? No assignment, no closing “;”. The code built and ran! The outcome was my view moving into strange positions during rotation for no apparent reason. Wow.

I finally had to do a diff to find it, I just couldn’t see it.

Categories
Development iOS Work Note

Work Note: When to share?

I do freelance work. As a freelance developer I’ve had times where I need to write code I know others could use. I use plenty of open source software, so I figure I should try to contribute something back.

That said, I’m working on a project right now that needs to parse RSS feeds. I know there are some existing RSS parsers available for Objective-C, but I’m going to write my own for a few simple reasons.

  1. I need it for this project
  2. I can reuse it later
  3. I’d like to give back
  4. I wanted to do something block based
  5. I wanted to publish it using CocoaPods

This exercise is primarily about two things; Sharing and self learning.Duct Tape, fixer of all things!

If I’m the only person that ever uses it, at least I’ve learned something new (packaging with CocoaPods) and I have something I can use again.

Update (6PM): I’ve published what I’ve completed. Some warnings. This code is very much as is. I’ve only tried it with well behaving RSS 2.0 feeds. The code definitely stands on the backs of giants. It depends on TouchXML to do all the hard work, all this code does is create RSS objects. Do not expect much.

I still need to add CocoaPods support and it could use a bunch of unit tests. I’ve done a few, but I can go a whole lot deeper.

Anywho, lots to do.

Categories
iOS Work Note

Work Note: UIButton and UITableViewCell contentView

I am not sure why I see this behavior but I am sure someone smarter than I am can explain it. I am creating a custom table view cell derived from UITableViewCell. In the viewDidLoad method I’m adding, amongst other things, a UIButton to the cell.

All of the UILabels I added to the cell were added to the contentView and display just fine, but the UIButton’s I added to it don’t work properly, you can see them, but no events fire.

Here’s how I’m doing it:

[self.contentView addSubview:self.fancyButton];

That doesn’t work. However, adding the button to the view, does work:

[self.view addSubView:self.fancyButton];

According Apple’s documentation for UITableViewCell contentView:

The content view of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.

If I add the button using Interface Builder, it works as expected, but in this case I’m building the cell in code. At some point I need to dissect a prototype Interface Builder based UITableViewCell to see what it does. I would imagine it places all subviews in the view, not the contentView.