Are You Being Energized or Drained?

Filed in iDevBlogADay, Miscellaneous | Comments (2) |

Things That Energize Me

Eric

EricYesterday I was in the basement talking with one of my sons. I heard laughter upstairs and went to see what was up — at the top of the stairs I found my grandson quickly crawling towards me. He had heard my voice and decided being with grandpa sounded like a pretty cool thing, and took off like a shot to come find me.

How great is that!

Often when he is around, a short work break turns into an extended session crawling around on the floor until my knees hurt. When that happens, I always return to my basement lair refreshed.


Making Physical Things

It has been a little while since I have done any significant woodworking, but I do have a decent set of tools and supplies in the garage. I love starting with nothing more than a vague idea and transforming raw pieces of wood into something with my own two hands (and some power tools!).

Creating physical things that never existed before is very cool, and seeing the finished product sitting on the workbench is satisfying.

Wilderness

GlacierNPI love spending time with my family, and some of my favorite times are our trips to the mountains, woods, or canyons. Being someplace where none of my technology works frees me in a unique way. Even a short visit to the wilderness can recharge a part of my mind and soul that I didn’t even realize were hurting.

A hike in the canyons of the southwest, the great woods of the north, or one of our great National Parks in the mountains inspires me in a way nothing else can.


Helping People

When someone I have taught demonstrates by their work or life that they “got it”, that gives me a good feeling. But, when they surpass anything I taught or helped with — that is really exciting.

When someone like that excels, their success spills over and puts gas in my tank.

Writing Useful Software

As much as I like seeing something physical take shape, crafting something out of nothing but thought is a uniquely enjoyable experience. When the pieces come together and fit just like I want; when I can look at what I have written and honestly say to myself, that turned out pretty well; and when others find what I have finished to be good — I am pleased, and that pleasure provides energy for the next round.

Things That Drain Me

Breaking Commitments

One of the requirements of being a responsible adult is making commitments and keeping them. When I can see no way to keep a commitment I made because of my poor planning or lack of understanding of what I was doing — I pile up stress points like crazy. If I have to go back to someone and explain that I can see no way to keep the commitment I willingly made earlier, it is a serious emotional drain and can turn into a downward spiral if I am not careful.

Making a Mistake That Hurts Someone Else

Mistakes happen. We all know that. If I mess up on something that primarily hurts me, I kick myself for a minute then get my head on straight and figure out how to correct it and move on. I really don’t waste energy on the “if only” stuff any more. But, if my mistake causes someone else extra work or pain, I cringe and struggle with figuring out how to make amends.

Repeatedly Failing To Reach A Goal

If I set a goal, whether formal or informal, and don’t reach it — I am usually able to rationally analyze what went wrong and decide how to proceed. But, if there is a long term goal that I seem to be getting no closer to, or repeat the “set goal, fail” cycle for the same goal too many times, it gets very discouraging.

Beating Discouragement

We all could make lists like these. Some of the items will change, but the pattern is part of being human. One of the dangers of discouragement is that it starts a negative feedback loop that can ruin me emotionally if left unchecked.

To be discouraged is “to be deprived of courage or confidence : be disheartened”. When my courage or confidence is low or non-existent, it can be very hard to break out of that cycle. Here are some things I can do to break discouragement’s nasty grip.

Separate The Objective Reality From Subjective Feelings

Emotions are a vital part of being human, and it does not help if I pretend they don’t exist or that they don’t matter. Unfortunately, emotions can be misleading or just plain wrong, and often lag far behind objective reality. I need to find a way to sort out what is real.

I need to work backwards from my feelings to the reality. I do something like the “Five Whys” on my emotions to help determine the root causes. Once I have identified the root causes of my discouragement I am in a better position to address them.

For root causes that are outside my control, I have to ask myself if I can really afford to let events like that control my life so deeply. At this point, I need to force myself to change my goals or expectations. If I am unwilling to make that change, I need to realize I am facing a downward spiral with no escape.

For root causes over which I have some control, I have to ask myself which is more important: the status quo those causes represent or my goal. It may be difficult to decide, and my end decision may be a hybrid, but once again, something needs to change or nothing will be solved.

Enlist The Help Of Objective Loved Ones And Friends

If I am having trouble sorting out the truth about my discouragement, enlisting an objective loved one or friend makes a big difference. Even the geekiest, most introverted people need others, and I am no different. It can be painful to ask for this kind of help, and I need to use discretion, but it may be the only way for me to see what is true and what is false.

Choose To Do Things That Energize You

I need to find those things that energize me. I cannot expect to remove destructive emotions without finding things to take their place. When I have a choice, I need to choose activities, relationships, and projects that will be encourage me to keep trying.

I need to find ways to take incremental steps towards my goals. When I see progress on a small scale, that enables me to envision success on a grander scale.

Be Decisive

It is a myth that I can have it all. I need to make choices about what is important to me, what I want, what I should do, and what I cannot do.

One aspect of leadership that applies to all responsible adults is that decisions must be made with incomplete information. I will never have all the information I want before I have to make a decision, and if I keep waiting for it, I will end up in “analysis paralysis”.

So.

  • Make a decision.
  • Be willing to live with the consequences of that decision.
  • When necessary, make changes.



After all, that is what it means to be a grown up.




This marks the beginning of my second run on iDevBlogADay. Once again, my thanks go out to all the participants, readers, but especially to Miguel. Thanks Miguel!

We all need the support of others to do our best work. Find other like-minded developers that will provide encouragement and motivation through local user groups, conferences or meetups. A great collection of indie iOS developers have helped me stay on track through meetups, 360iDev, twitter, and iDevBlogADay.

I regularly attend Cocoa/iPhone developer meetups in Cincinnati, Ohio and Columbus, Ohio. If you are in the central or southwest Ohio area, come join me at either monthly meetup:

If you depend on iOS development for your livelihood, or would like to get to that point — you really need to attend a conference dedicated to helping you get better, and I can think of no better conference for that purpose than 360iDev — you should register today!. Much of what I am able to do professionally is due to the things I learned and the people I met there.

Finally, here is a little more information about me, Doug Sjoquist, and how I came to my current place in life. You should follow me on twitter and subscribe to my blog. Have a great day!

Sample Xcode 4 project with embedded GHUnit and OCMock frameworks

Filed in iOS Development, Miscellaneous | Comments (3) |

My previous post described building an Xcode project template with GHUnit and OCMock support built-in.

Unfortunately, the project template structure for Xcode 4 is significantly different, and even though I am working almost exclusively in Xcode 4 now, I have not taken the time to create a new version of the template.

So for now, I went a little old school and created and empty base project and then just copy the directory and rename things to start a new project.

This zip file is roughly the same contents as what the project template creates in Xcode 3, and I just verified that I can open it up cleanly, build, and run both test targets in Xcode 4. I hope it helps.

http://www.sunetos.com/code/EmptyXcode4GHUnitOCMock.zip

Creating an Xcode project template with GHUnit and OCMock

Filed in iOS Development | Comments (2) |

I use GHUnit and OCMock in my app development, but each time I set up a new project in the past, it felt klunky and error prone. I either copied an old one to start and renamed and deleted things, or I created a new one and dragged chunks from old projects into it. I grew weary enough of this process that I decided it was time to create an Xcode project template with my typical setup.

I recently created an Xcode project template to do all this, and I decided to write a step-by-step description to help others do something similar. It is a simpler project than my template, but covers all the required steps. It might be useful to you as-is, or perhaps it just gives you the one missing piece in your battles with GHUnit, OCMock, or project templates.

These instructions are based on:

and will cover these steps:

  1. Create a base application project
  2. Add a GHUnit based application test target
  3. Add OCMock to the application test target
  4. Create an Xcode project template from the project

General comments

I highly recommend creating a local source control project to save your work as you progress. Commit your changes often enough to make things easier on yourself. My practice is to do one thing at a time, get it working, and commit to my local .git repository. Every so often, usually after a major subtask is complete, I will also push my changes to a remote git repository.

These instructions will create a project structure with all files stored in the actual project directory, including the GHUnit and OCMock frameworks. It is better for your template to embed its dependencies rather than depend on external references.

These instructions assume everything we create or download will be in the directory ~/xcpt, but feel free to put them wherever you like.

After each step in the process, you should do a clean, build, and run for each target to validate the configuration and dependencies, and make sure your VCS includes all files and you have committed your changes.

I create projects and templates with more structure and configuration options than we will cover here. In order to focus on the core issues, I will be creating a simpler project structure than I normally use. I would suggest you create the simple project and template here first to ensure the steps work for you. Then create a customized version that matches how you normally set up your projects.

We will use the name TemplateBase for our project and derive several targets and file names from it. You can choose whatever name you wish, but for ease of editing the final project and turning it into a template, be consistent in your naming.

There are many more options for GHUnit, OCMock, and project templates, but they are outside the scope of these instructions. For more information, see the Other Links at the end of this post.

1. Create a base application project


xcptStep1a.pngThese instructions start with the Tab Bar Application template, but you should be able to build your template based on any of the standard application templates.

This step is straightforward but provides a baseline on which we can build our project.

  • Create a new subdirectory xcpt in your home directory
  • Open up Xcode, and create a new project based on the Tab Bar Application template
  • Save the project as TemplateBase in ~/xcpt
  • Make sure the project builds and runs in the simulator without error

If you like positive reinforcement, congratulations, step 1 is complete! If not, let’s move on anyway.

2. Add a GHUnit based application test target


xcptStep2a.pngFirst, we need to add a test target to our project. GHUnit runs as as a standard application target, so create a new application target named TemplateBaseTests.


xcptStep2b.pngAdd the existing frameworks in our project to this target by selecting them as a group, right-clicking them, and checking TemplateBaseTests in the Target Memberships list.

Next, we need a copy of GHUnit. Download the latest version, 0.4.27, from github, and unzip it into ~/xcpt.


xcptStep2c.pngOpen the ~/xcpt folder in Finder and drag the GHUnit.framework directory to the Frameworks group in your project. Make sure you:

  • Check “Copy items into destination group’s folder (if needed)”
  • Uncheck TemplateBase in the Add to Targets window,
  • Check TemplateBaseTests in the Add to Targets window


xcptStep2d.pngNow create a new group called “Test Classes”. Edit the info for the group, and under the Target tab, assign this group to TemplateBaseTests.


xcptStep2e.pngCreate a new class named SampleTestCase in the Test Classes group. We do not need a header file for our unit test classes, so uncheck “Also create SampleTestCase.h”.


Replace the entire contents of the file with the following code:

#import <GHUnit/GHUnit.h>

@interface SampleLibTest : GHTestCase { }
@end

@implementation SampleLibTest

- (void)testSimplePass {
	// Another test
}

- (void)testSimpleFail {
	GHAssertTrue(NO, nil);
}

@end


xcptStep2f.pngOpen up the info dialog for the TemplateBaseTests target, and select the Build tab. Select “All configurations”, then find the “Other Linker Flags” setting and add “-all_load” and “-ObjC”.

Now select TemplateBaseTests-Info.plist and clear the value for the “Main nib file base name” property.

Our last step is to download the file GHUnitIOSTestMain.m and add it to our Test Classes group. Make sure you actually copy the file into the folder when you add it, we need this file to be a part of our directory structure for use in the template.


xcptStep2g.pngWe are now ready to run our application tests. Change the active target to TemplateBaseTests, switch to the Simulator, and run the target. If everything is configured properly, your test application should start. Click the Run button, and you should see something similar to this:

Once you have the TemplateBaseTests target running correctly, double check your dependencies by doing a clean, build, and run on the TemplateBaseTests target.

3. Add OCMock to the application test target

Now that our appplication test target works, we want to add support for OCMock. Something changed in Xcode since 3.2.3 and older methods of integrating OCMock appear to have quit working. I have talked with developers who struggled with getting it working and gave up, but I have not had any problems with the method I use.

The method that works consistently for me is to add the OCMock.framework and the libOCMock.a to our test target, with one caveat: the library file that is part of the normal OCMock distribution does not work with iPhone projects, we need the library file that is part of the iPhone example project.


xcptStep3a.pngFirst, download the standard installation file, ocmock-1.70.dmg and open it in Finder. Drag the OCMock.framework from the Release folder to the Frameworks group in your project. As with the GHUnit framework make sure you:

  • Check “Copy items into destination group’s folder (if needed)”
  • Uncheck TemplateBase in the Add to Targets window,
  • Check TemplateBaseTests in the Add to Targets window

The library file in the dmg file will not work with your iPhone project, so we need the one from the iPhone example project. Download the file libOCMock.a from the example project page, open it in Finder, and drag it to the Frameworks group in your project. As with the frameworks, make sure to copy the file, and include it in the TemplateBaseTests target.

Now we need to add some test cases that use OCMock to our SampleTestCase. Replace the entire contents of the SampleTestCase.m with the following code:

#import <GHUnit/GHUnit.h>
#import <OCMock/OCMock.h>

@interface SampleLibTest : GHTestCase { }
@end

@implementation SampleLibTest

- (void)testSimplePass {
    // Another test
}

- (void)testSimpleFail {
    GHAssertTrue(NO, nil);
}

// simple test to ensure building, linking, and running test case works in the project
- (void)testOCMockPass {
    id mock = [OCMockObject mockForClass:NSString.class];
    [[[mock stub] andReturn:@"mocktest"] lowercaseString];

    NSString *returnValue = [mock lowercaseString];
    GHAssertEqualObjects(@"mocktest", returnValue, @"Should have returned the expected string.");
}

- (void)testOCMockFail {
    id mock = [OCMockObject mockForClass:NSString.class];
    [[[mock stub] andReturn:@"mocktest"] lowercaseString];

    NSString *returnValue = [mock lowercaseString];
    GHAssertEqualObjects(@"thisIsTheWrongValueToCheck", returnValue, @"Should have returned the expected string.");
}

@end


xcptStep3b.pngWe are now ready to run our application tests. Change the active target to TemplateBaseTests, switch to the Simulator, and run the target. If everything is configured properly, your test application should start. Click the Run button, and you should see something similar to this:

Once you have the TemplateBaseTests target running correctly, double check your dependencies by doing a clean, build, and run on the TemplateBaseTests target.

4. Create an Xcode project template from the project

Creating a basic Xcode project template from your project requires some simple steps:

  1. Copying the project’s directory structure to the right place
  2. Renaming some files
  3. Changing references to your base project name in all the files in the project

Xcode looks for project templates in multiple locations, but the best place to put your new template is in the directory:

~/Library/Application Support/Developer/Shared/Xcode/Project Templates/Application

By placing your template here, future Xcode upgrades should leave it alone.

If this directory does not exist, go ahead and create it. Copy your project directory “~/xcpt/TemplateBase” into this directory. The name of the directory is the name that Xcode will use when it displays it under “User Templates”, so you can rename the top level directory name to whatever you want displayed.

One minor cleanup item at this point is to remove the files “username.pbxuser” and “username.perspective3″ from the TemplateBase.xcodeproj directory. You only need the “project.pbxproj” file.

At this point if you open Xcode and select New Project from the menu, your template will display in the list, and will even be usable. But, we do not want our new project to use file names like “TemplateBaseAppDelegate”, we want the file names to match whatever our new project name is, so we need to use the special file naming and tagging conventions that Apple uses in its templates.

There is a good post on CocoaDev that lists the available tags. When creating a new project, Xcode will do the appropriate text substitution in file names and contents based on these tags. Apple’s current style is to use three underscores “___” as delimiters. The CocoaDev post uses the older style of delimiters («tagname»), but the names are still the same.

For our example, we will only use two tags: “___PROJECTNAME___” and “___PROJECTNAMEASIDENTIFIER___”.

We cannot use Xcode to edit names since we will be changing contents of the internal structure of an Xcode project. Use command line tools or whatever editor you have on hand. I like to use TextMate for this sort of thing since it allows me to open an entire directory as a group and make changes en masse.

Before we edit any file contents, we need to rename the files in our project template directory to use the appropriate tag name. In the ‘~/Library/Application Support/Developer/Shared/Xcode/Project Templates/Application/TemplateBase’ directory, rename these files:

Existing file New name
Classes/TemplateBaseAppDelegate.h Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h
Classes/TemplateBaseAppDelegate.m Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.m
TemplateBase-Info.plist ___PROJECTNAMEASIDENTIFIER___-Info.plist
TemplateBase.xcodeproj ___PROJECTNAME___.xcodeproj
TemplateBase_Prefix.pch ___PROJECTNAMEASIDENTIFIER____Prefix.pch
TemplateBaseTests-Info.plist ___PROJECTNAMEASIDENTIFIER___Tests-Info.plist

At this point, if we created a project from this template, it would be broken — our filenames would be inconsistent with the internal references to those files, so we now need to edit all the references to use tag names as well. These files all contain the string “TemplateBase” and need to be edited.

  • Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h
  • Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.m
  • Classes/FirstViewController.h
  • Classes/FirstViewController.m
  • FirstView.xib
  • MainWindow.xib
  • SecondView.xib
  • ___PROJECTNAME___.xcodeproj/project.pbxproj
  • ___PROJECTNAMEASIDENTIFIER____Prefix.pch
  • main.m


xcptStep4b.pngI will use TextMate in my instructions, but any editor should do. Just make sure you don’t miss a file.

Open the top level directory for your template using TextMate. Evidently TextMate recognizes the framework and Xcode project file directories, so it does not add them by default. We need to add just the Xcode project file directory to our list by opening it up specifically inside this TextMate session. Right click on the empty space below the existing file names, select “Add Existing Files”, then select the directory name “___PROJECTNAME___.xcodeproj”.

Now do a global find and replace, changing all references of “TemplateBase” to “___PROJECTNAMEASIDENTIFIER___”. Save your changes, and your project template should be complete.

You should now be able to create a new project based on this template. Run both the application and test targets in the simulator on your newly created project to verify that.

Other Links

I have kept the instructions pretty minimal in this example, but there are obviously a lot of additional things you can do. Here are several links I found useful while working with GHUnit, OCMock, and Xcode project templates. If you had any problems with my example, perhaps one of these links will help you better!

Zip files of Project Templates

GHUnit

OCMock

Xcode Project Templates


We all need the support of others to do our best work. Find other like-minded developers that will provide encouragement and motivation through local user groups, conferences or meetups. I regularly attend Cocoa/iPhone developer meetups in Cincinnati, Ohio and Columbus, Ohio. If you are in the central or southwest Ohio area, come join me at either monthly meetup:

Also, here is a little more information about me, Doug Sjoquist, and how I came to my current place in life. You should follow me on twitter and subscribe to my blog. Have a great day!

Old Year, New Year, Old Stuff, New Stuff!

Filed in iDevBlogADay, Miscellaneous | Comments Off |

Old Year, Old Stuff

I have been an independent developer for over twelve years, using a variety of tools, platforms, and languages. I really love being on my own, even through the slow periods when I wondered if I would find any new projects to work!

Breaking away from corporate life might not be for everyone, but if you are thinking about it, I encourage you to keep working towards that goal. Being independent while my kids were growing allowed us to do many things as a family that I would not otherwise have been able to do. It also put me in a position to work on some very cool projects for different clients over the years.

Old Year, New Stuff

Twelve months ago, I set a goal of having close to half my work be iOS based by the end of the year. I did not quite reach that goal, but I can definitely see it happening in the near future.

I have really matured in my iOS development by hanging out with very smart and sharing people at 360iDev conferences, local user groups and meetups, and through twitter. Thanks to all who taught, wrote, or otherwise shared great stuff!

New Year, Old Stuff

I have gone through many changes in life, both personally and professionally, but very few have been abrupt ones. I still expect to continue on in some fashion with projects I have been working this past year. As some major projects from the past year wind down this year, it will be interesting to see what comes next.

New Year, New Stuff

This coming year will be one of those gradual changes as I move into more and more mobile development, both iOS and Android, over the coming months. I anticipate being very busy for the first few months of the year, and then seeing what happens.

iDevBlogADay.com

Today’s post marks four complete months for my participation in iDevBlogADay, and with the new work I will be involved with over the next few months, this seems an appropriate time to hand over my coveted Sunday slot to the next victim. I’ve really enjoyed being a part of iDevBlogADay.com — it has been the primary support technique to get me writing regularly again, and for that I am very thankful.

Participating has taught or reminded me of several things:

  • Just like software, good writing is work;
  • Writing usually takes longer than I think and rarely turns out exactly like I planned;
  • There is nothing like a deadline to motivate me to action;
  • Writing about what I am learning helps me understand it better;
  • The developer community in general, and the iOS developer community in particular is great!

Thanks Miguel!

Miguel, thanks so much for the work you put into setting up and maintaining iDevBlogADay, I appreciate it very much. For those who have read, commented on, and retweeted my posts — thank you, I hope you found some useful nuggets along the way.

I still plan on posting twice a month, though not on Sunday. You should subscribe to my blog and hold me accountable to this.

Please follow me on twitter if you are interested in what comes of all this new stuff!

Merry Christmas and Happy New Year!

Animating Multiple Virtual Pages Using a NIB-based View

Filed in iDevBlogADay, iOS Development | Comments (13) |

Today’s post is a simplified version of some work I’m doing for a client.

For the client app, I need to browse a set of data using a NIB-based view, but do so by swiping left and right in the context of a parent view — a similar effect as Apple’s weather utility app. I didn’t explore how Apple actually does it, but the method I am using is pretty straightforward.

Overview

Demo2010Dec19_pic1.pngThis simple app displays a view for a single item at a time from an ordered list of simple domain objects. A UISwipeGestureRecognizer detects swipe events which are used to animate items on and off the parent view.

The previous view is off screen to the left, and the next view is off screen to the right. Both of these are preloaded so that when a swipe event is recognized, there is no delay while loading data for the item to be animated onto the parent view. The app cycles through three instances of the same NIB-based view controller as the user swipes.

For instance, given a list of 7 items, the app starts in this state:

  • The center view displays item A;
  • The view off screen to the right is preloaded with item B;
  • The view off screen to the left is preloaded with the last item, item G;

In this state, when a left swipe event is recognized, I want it to be interpreted as “move the currently displayed item (A) to the left and show me the next item (B)”. What happens is this:

  • The position of the center view is animated to the left off screen position;
  • The position of the right view is animated to the center on screen position;
  • The old center view becomes the new left view;
  • The old right view becomes the new center view;
  • Since the old left view is “pushed” farther to the left, it becomes the new right view;
  • The new right view is loaded with the appropriate data from the list.

A mirrored set of events happens on a right swipe event. (The app treats the list circularly, so there is no right or left edge of items.) The app also includes a tap recognizer which is used to update the tap count for each item to demonstrate how you can maintain state as views are cycled.

Handling Gestures

Each instance of SampleViewController has three gesture recognizers, swipe left, swipe right, and tap. Each also retains a reference to it’s currently displayed item when it is loaded.

The behavior for tapping is simple. When a tap is recognized on a view, the tap count for that view’s item is updated. Nothing needs to happen outside the current view and item.

The behavior for swiping is slightly more involved. Since a swipe is supposed to initiate animating the current view off the screen and a new view into the center, it would be messy for the current view to handle the animation. The best solution is to have the parent view handle the animation, since it already owns all the items and views necessary.

The cleanest way to accomplish this is by creating a simple protocol for delegating the behavior. SampleViewController.h includes the protocol definition, and adds an ivar for the delegate itself.

SampleViewController.h

#import <UIKit/UIKit.h>
#import "SampleData.h"

@class SampleViewController;

@protocol SampleViewControllerDelegate
- (void) handleSwipeLeftFrom:(SampleViewController *) source;
- (void) handleSwipeRightFrom:(SampleViewController *) source;
@end

@interface SampleViewController : UIViewController {
    UILabel *sampleIdLabel;
    UILabel *nameLabel;
    UILabel *tapCountLabel;
    UIImageView *imageView;

    SampleData *sampleData;

    id<SampleViewControllerDelegate> delegate;

    UISwipeGestureRecognizer *swipeLeftRecognizer;
    UISwipeGestureRecognizer *swipeRightRecognizer;
    UITapGestureRecognizer *tapRecognizer;
}

@property (nonatomic, retain) IBOutlet UILabel *sampleIdLabel;
@property (nonatomic, retain) IBOutlet UILabel *nameLabel;
@property (nonatomic, retain) IBOutlet UILabel *tapCountLabel;
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@property (nonatomic, retain) SampleData *sampleData;
@property (nonatomic, retain) id<SampleViewControllerDelegate> delegate;

- (void) loadSampleData:(SampleData *) aSampleData;

@end

and in the implementation simply forwards to the appropriate method of the delegate:

SampleViewController.m snippet

- (void)handleSwipeLeftFrom:(UISwipeGestureRecognizer *)recognizer {
    [delegate handleSwipeLeftFrom:self];
}

- (void)handleSwipeRightFrom:(UISwipeGestureRecognizer *)recognizer {
    [delegate handleSwipeRightFrom:self];
}

- (void)handleTap:(UITapGestureRecognizer *)recognizer {
    self.sampleData.tapCount += 1;
    [self updateTapCountLabel];
}

The delegate owns the three instances of SampleViewController, so is able to properly manage the animation between views:

Demo2010Dec19ViewController snippet (SampleViewControllerDelegate implementation)

- (void) handleSwipeLeftFrom:(SampleViewController *) source {
    if (source == centerSVC) {
        [UIView animateWithDuration:SLIDE_DURATION
                         animations:^{
                             centerSVC.view.frame = leftFrame;
                             rightSVC.view.frame = centerFrame;
                         }];

        // move untouched view to other side, and adjust names for next cycle
        leftSVC.view.frame = rightFrame;
        SampleViewController *tempSVC = centerSVC;
        centerSVC = rightSVC;
        rightSVC = leftSVC;
        leftSVC = tempSVC;

        // cache next sample
        currentIdx = [self checkIdx:currentIdx+1];
        int rightIdx = [self checkIdx:currentIdx+1];
        [rightSVC loadSampleData:[samples objectAtIndex:rightIdx]];
    }
}

More to be done

There is much that can easily be done to enhance this example, some of which I will be adding to my client’s app. Things like:

  • Adding a UIPageControl at bottom
  • Adding fade-in/fade-out toolbars for extra navigation (like the Kindle App)
  • Implementing momentum on swiping so fast swiping moves past multiple views

Hopefully this helps someone get over the hurdle of animating between sibling views. I know I made several simplifications to my original code while preparing the sample code for this blog.

You may download the sample project and use the code however you wish.

Merry Christmas!!

I wish all of you a very Merry Christmas.

Make sure you take time to relax with family and friends this week, but also take some time to read and consider the original Christmas story.


We all need the support of others to do our best. Find other like-minded developers that will provide encouragement and motivation through local user groups, regular conferences or meetups. This post is part of iDevBlogADay which has really helped me stay on track with my writing and my iOS projects.

Also, here is a little more information about me, Doug Sjoquist, and how I came to my current place in life. You should follow me on twitter and subscribe to my blog. Have a great day!

Think, Think, Think…

Filed in iDevBlogADay, Miscellaneous | Comments (5) |

Think, Think, Think...

Think, Think, Think…

One of my favorite shows to watch with my young children was Winnie The Pooh — perhaps because I had good memories of watching the classic TV specials from when I was a child.

I loved the simple, happy nature of Pooh, but one downside of being stuffed with fluff is that it can be hard to think. Pooh occasionally worked very hard at it, with very limited results. I’m pretty sure my head isn’t stuffed with fluff, but some days my thinking doesn’t seem to get me any farther than Pooh’s did.

Lost in Thought — An Incredible, Productive Day

In developing software, my primary tool is my mind. Languages, frameworks, IDE’s, and editors all are important — but without the right mind to use them, and the right frame of mind, they are worthless.

My family can tell you that watching me work some days is incredibly boring. Much of those days is spent staring at the screen, at some scribbles on notepaper, or blankly into space. Those are often the days where I make the most progress.

My most productive days are when I’m so deep in thought that I don’t even remember to eat. I love those days. It’s like I can see the entire program as a single entity in my mind–I can turn it over and around, zoom in and out, pull one part out, graft something new in–it’s a incredible feeling. I wish they happened more often!

Holding it in your head

Paul Graham describes that feeling as “Holding a Program in One’s Head“. He writes:

They do more in their heads: they try to understand a problem space well enough that they can walk around it the way you can walk around the memory of the house you grew up in. At its best programming is the same. You hold the whole program in your head, and you can manipulate it at will.

He goes on to list ways to help load the entire program into your head. I may quibble about some items, but the point is valid. In order to get to that incredible, lost in the world of my program point more often, I need to figure out deliberate steps that move me away from Pooh-thinking and into that magical place.

From Pooh to TRON

There are a number of tactics I use to de-fluff my mind and achieve TRON-ness with my program, but none of them work every time, and each of them are subject to exceptions.

Working at a consistent level

  • I try to stay at a consistent level of abstraction as long as possible, switching costs between working on high-level designs and low-level implementation details can be high.
  • Rather than switching back and forth between competing projects throughout the day, I try very hard to spend most of the day on a single project — even if it is not the exact same task.

Managing distractions

  • Some interruptions are predictable, so preempt them and deal with them before they attack. (If you work at home, this may mean keeping up properly with your share of household duties before you begin.)
  • Have a notebook or software tool that allows you to quickly record any unrelated items demanding attention. Do not do any real thinking about it, simply record it. Once recorded, dismiss the thought and go back to work, those items are attacks on your concentration — do not give ground. (This only works if you have a reliable system for addressing those items, otherwise your mind will not let go.)
  • After you finish a session, deal with the items you recorded appropriately if necessary. That way you train yourself to trust that you really will “deal with that later”.
  • Schedule times or days where coworkers or family know you need to be left alone, in cooperation with them of course! On-going communication is key.
  • If twitter, facebook, news readers, or email keep pulling you away — just STOP IT.

Achieving Flow quickly

  • When you finish a session, or are interrupted, record what you are thinking or doing so that you don’t lose all your context. (See the excellent advice in the post “the interruptible programmer“.)
  • Use music, headphones if necessary. I listen to a lot of different kinds of music, but my “flow” music tends to fade into the background quickly and support my thinking, rather than require me to pay attention to it directly. For me, that usually means minimal or no lyrics, but everyone is different in that regard.
  • If you are actively working on code, then leave it in a mildly broken state. Put some notes directly in the source file where you left off so it won’t compile, add a failing unit test, something to draw your attention back to the point you left.

Manage your expectations

I don’t believe it is possible to be so consistent at your work, that you never suffer from Pooh-thinking days. So don’t set your expectations so high that your disappointment becomes a serious distraction all by itself.

You goal should be improvement, and perhaps even that “perfect” day — but don’t let the fluffy-head days get you down. There’s a good chance tomorrow will be a better day.


We all need the support of others to do our best. Find other like-minded developers that will provide encouragement and motivation through local user groups, regular conferences or meetups. This post is part of iDevBlogADay which has really helped me stay on track with my writing and my iOS projects.

Also, here is a little more information about me, Doug Sjoquist, and how I came to my current place in life. You should follow me on twitter and subscribe to my blog. Have a great day!

Open Source iOS CoverFlow Implementations

Filed in iDevBlogADay, iOS Development | Comments Off |

For my personal iOS development, I have a technical experiment and exploration todo list. It includes techniques I need to get better at, open source packages to investigate, that sort of thing.

I try to keep the items on the list small enough to do enough prototyping in a single evening to satisfy my curiosity. That way I am willing to move on during my next exploration session. The point is not usually proficiency, but enough familiarity to decide if the technique or framework merits further study. I often keep the code around as a reference, but it is definitely throwaway code, so it’s in a separate folder than “real” code.

One of the items on my list was to find and investigate CoverFlow clone examples floating around the intertubes. I found several that were based on Apple’s private APIs or were old enough that I was not interested. But, I did find two that I spent some time investigating.

OpenFlow, a CoverFlow clone developed during iPhoneDevCamp

The first was OpenFlow by Alex Fajkowski, released at iPhoneDevCamp in August, 2009. It is hosted on GitHub, but it does not look like it has been updated since then.

There is sample code included with the OpenFlow download, but it does not have a simple, quick-start example to get an initial feel for the package. Fortunately, others have written posts with some simple examples, two I looked at were:

A simple example by Julios Barros’ (@juliobarros).

And another simple example, but with more pictures and step-by-step details.

I liked OpenFlow well enough, but the current implementation did not allow for flicking through multiple covers. It behaves a little more like iTunes on the mac, not like browsing albums on the iPhone iPod app. Fortunately, my other “find” did have better flicking behavior, with tweakable momentum settings.

FlowCover, an easy to use OpenGL ES based CoverFlow clone

My other “find”, FlowCover by William Woody is essentially one OpenGL ES class with a simple helper class for data caching.

I like simple. Since I am likely to tweak the behavior of whatever I find, the simpler and cleaner the starting point — the better.

I added the two classes to my prototyping base project, and I was off and running. FlowCover works pretty much as expected, behaving smoothly and simply. The only change I made to FlowCover.m was to allow for different scaling when in landscape and portrait modes. Other than that, it worked just as I wanted.

Conclusion

If you are interested in adding some Cover Flow type behavior to your app, I recommend checking out both projects.

OpenFlow is based on UIKit, and has more features than FlowCover.

FlowCover is based on OpenGL ES, has few features, but behaves a little more like I expected Cover Flow on an iPhone to behave.

Either is a good choice, but my needs are simple enough right now that I think I will be using FlowCover.


As an indie developer, one of the best things you can do is to find like-minded developers that will provide encouragement and motivation while pursuing a commitment. A great collection of indie iOS developers have helped me stay on track, many of them are either developers associated with iDevBlogADay, or those I have met through the 360iDev conferences. I also encourage you to find local NSCoder nights, developer meetup groups, or other user groups to keep your motivation on track. If there aren’t any meeting locally, try to find one other developer and start one.

Also, here is a little more information about me, Doug Sjoquist, and how I came to my current place in life. You should follow me on twitter and subscribe to my blog. Have a great day!

Are You A Gamer, A Tinkerer, Or A Maker?

Filed in Miscellaneous | Comments (3) |

Gamer? Me? Not So Much

I have a confession: I am not very good at playing video games. Most of my time on the family XBox 360 is playing multiplayer games with my kids, and on that machine my gamer tag is “Target”, so that should give you a good idea of my proficiency at Halo, Call of Duty, or whatever the game of the week is around here.

I don’t have any problem with folks who love to take the time to beat games. Both of my college age sons love the challenge of a good game when they have the time.

I guess I’m just not a gamer at heart.

A Tinkerer At Heart

I think I could be a lot better at video games, but that would require a lot more time playing by myself than I care to give. My main problem is I am more interested in how it was done than I am in finishing whatever task is set before me. I would rather try to figure out how to do even a small part of what I see, than to finish playing. That same all tinker, no finish, bleeds into other areas of my life at times as well.

I love to tinker. On my mac, in the garage, in the yard, wherever. Doing something for the first time, usually without instructions and just a vague idea of what I want is one of my favorite ways to waste some time.

I have other marks of a tinkerer as well. I’d rather start something new than take something that I think is “good enough” and finish and polish it. Every time a new idea crosses my path, I’m tempted to play too long with the new shiny instead of pressing forward and finishing the old.

I Want To Be A Maker

I still feel the call of the tinkerer within, but I am getting better at resisting. Both personally and professionally, my goal is to increase my finishing percentage, and I am reasonably pleased with my progress.

I do not want to be known as just a tinkerer, I want to finish things well.

I want to be known as a maker, a maker of good things.

p.s.

Now that I’ve come clean about my abysmal gamer credentials, I only hope that the geek overlords do not find out and revoke my geek card.

Winston Churchill's Keys To Success

Filed in iDevBlogADay, Miscellaneous | Comments Off |

One of the difficulties in discussing success is that each of us may have a different definition. I believe that ultimate success in life depends on my relationship with my creator1, but I also believe there are many aspects of success that all of us can agree on.

Lessons from Winston Churchill

I would not equate building an application or creating a game with the major events surrounding Winston Churchill’s life and career, but there are lessons we can apply from what he said and wrote.

On Failure

“Success is the ability to go from one failure to another with no loss of enthusiasm.”

“Success is not final, failure is not fatal: it is the courage to continue that counts.”

Learn from your failures rather than let them discourage you from continuing.

On Quitting for the Wrong Reasons

“Never give in. Never give in. Never, never, never, never–in nothing, great or small, large or petty–never give in, except to convictions of honor and good sense. Never yield to force. Never yield to the apparently overwhelming might of the enemy.

There are times to quit and there are times to persevere.

It is difficult to tell the difference, but if you think it might be time to quit, wait until you are thinking clearly and can evaluate the situation properly before making that decision.

On Criticism

“Criticism may not be agreeable, but it is necessary. It fulfills the same function as pain in the human body. It calls attention to an unhealthy state of things.”

Not every bit of criticism is valid, but I have found that most criticism contains at least a kernel of truth — find that kernel and decide if you need to make corrections.

On Mediocrity

“I am easily satisfied with the very best.”

Try very hard not to settle for mediocre results. Often it is better to cut something out completely rather than include some half-baked feature.

On Difficulties

“Mountaintops inspire leaders but valleys mature them.”

“The pessimist sees difficulty in every opportunity. The optimist sees the opportunity in every difficulty.”

Sometimes the only reason one person succeeds where others have tried and failed is simply because they pushed on through the valley to the other side when no one else did.

On Worries

“When I look back on all these worries, I remember the story of the old man who said on his deathbed that he had had a lot of trouble in his life, most of which had never happened.”

“Let our advance worrying become advance thinking and planning.”

Do not focus on things that might happen. You have enough things that are happening right now that you should handle.

Final Thoughts

Winston Churchill experienced things I never will, through times that I hope to never see.

But, his perspective and wisdom, though not perfect, can be invaluable when thinking about success. I hope you found a nugget that helps you this week.


As an indie developer, one of the best things you can do is to find like-minded developers that will provide encouragement and motivation while pursuing a commitment. A great collection of indie iOS developers have helped me stay on track, many of them are either developers associated with iDevBlogADay, or those I have met through the 360iDev conferences. I also encourage you to find local NSCoder nights, developer meetup groups, or other user groups to keep your motivation on track. If there aren’t any meeting locally, try to find one other developer and start one.

Also, here is a little more information about me, Doug Sjoquist, and how I came to my current place in life. You should follow me on twitter and subscribe to my blog. Have a great day!



1. Matthew 16:25-26 “For whoever would save his life will lose it, but whoever loses his life for my sake will find it. For what will it profit a man if he gains the whole world and forfeits his soul? Or what shall a man give in return for his soul?”

Reply from Ohio Senator Sherrod Brown in response to my email about TSA

Filed in Miscellaneous | Comments (0) |

I sent emails to my senators yesterday through their websites, and to the subcommittee leadership. My points were the scanners were intrusive, most likely a waste of money better spent on other forms of security, and that the TSA pat downs were highly offensive.

Sherrod Brown is the first to reply. Evidently he does not see much of an issue. Here is his email, without further comment.
—————————————-

Dear Mr. Sjoquist:

Thank you for sharing your views about the use of millimeter-wave scanners, also known as body image scanners, at airports nationwide.

The Transportation Security Administration (TSA) is increasing the number of millimeter-wave scanners in airports around the country. This new technology is able to detect concealed plastic and ceramic weapons as well as explosives that evade traditional metal detectors.
However, passengers who feel uncomfortable being screened by the body image scanner may decline to go through and will be patted down by a TSA officer as an alternate security measure.

I support bolstering the safeguards in place to prevent terrorists from entering our country. However, it makes sense to explore whether there are strategies other than millimeter-wave scanners that could be employed to discover concealed explosives and other weapons that are not detectable by traditional methods. Should relevant legislation be considered by the Senate, I will keep your views in mind.

Thank you again for getting in touch with me.

Sincerely,

Sherrod Brown
United States Senator

Stay connected with what’s happening in Congress. Sign up here for regular updates on the issues you care about the most: http://brown.senate.gov/newsletter/landing