Tech and a few other things RSS 2.0
# Thursday, April 25, 2013



Anyone who has written an application that interacts with an API knows it will invariably fail you and if luck has it’s way it will be at a time that will make you look unfavorable. Let’s move on.

The best way to mock a response is to intercept the response and inject a controlled predefined response back into your code. This allows you to never change the working code base.  In steps mocking for iOS using NSURLProtocol.  It’s a great tool, but NSURLProtocol’s documentation doesn’t make it super clear on how to use it, ok it kinda does, but abstraction can always make life a little easier. In steps Mocktail, Square, and this guy (https://twitter.com/puls). Add Mocktail to your project, and implement it with a few simple lines of code. I recommend putting it in the app delegate, possibly with some flags in your project file to exclude the code when doing a release. Also remember to exclude the testing files when you do a release build. I went ahead and added the "Mocktail" directory to Sub-Directories to Exclude in Recursive Searches for a Release build. You can see it in the Build Settings.

At any rate I have created a sample project that gives you an example on how to use it. You can get it here.

Also, completely unrelated, today, Apple  sold out it’s WWDC 2013 in about 2 minutes and I didn’t get a ticket as a result i’m going through the many stages of grief.
Thursday, April 25, 2013 2:36:16 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Objective C | Unit Testing | WWDC | xCode
# Thursday, February 28, 2013


WWDC can you smell it? Can you taste it? NO? Well then you will probably miss it. If your heart is not fully into this event it will pass right on by before you even know the tickets went on sale. As an example, last year the event of 5,000 people sold out in the first 45 minutes of the tickets being released for sale.

Sooo you need to know when tickets go on sale and you need to know it in minutes. Well fellow coders, there is an app for that. Check out http://wwdcalerts.com/ I also recommend getting some twitter monitoring tools to notify you or simply schmooze with someone at Apple who is in the know.

Little advice, ask your manager for permission long before the event, tell him you don't know when they will go on sale, but you need to know he will be cool with you buying them the minute they do go on sale. Do it now, just get up and get it done.
Thursday, February 28, 2013 9:16:01 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
apple | Apple TV | iPad | iphone | iphone | Objective C | WWDC | xCode
# Sunday, November 04, 2012
Solution:
Open organizer, select your device, select “Applications” in under your device on the right, select the application you want to look at the SQLite database on, click the download button at the bottom.




Once you have downloaded the file select show file packet contents. In the finder window that opens up look under the documents folder. In this folder you should be able to find the database. It will be the file with the “sqlite” extension. Next, you can download SQLite Studio (download link). It may tell you you need to run in 32 bit mode (easy, right click/ctrl click and select “Get Info” then select 32 bit mode).





View your sql data.

Explanation:
I’ve found this is very helpful when you need to see a large amount of data and want to organize it and search through it, for example, say you are storing a large amount of retailers and want to see how they are grouped together via their region tag you gave them. However, if you are examining just a single record it might be better to use, xCode debug and print out a single record.

Let me answer the first question you are probably asking: Is there a way to examine the Core Data - SQLite database on my iPhone while I’m debugging. Sadly, at this moment, the answer is no.

Sunday, November 04, 2012 6:05:59 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Core Data | SQLite | Tools | xCode
# Monday, September 24, 2012
March 6th 2008, was the very first day the iPhone SDK was made public. Since then, xCode has come a long way with it’s tools. As mobile development becomes less and less of a niche expertise so do the tool sets, which brings me to the focus of this post. Testing iPhone applications. From what I have seen most shops use the “I did this, then that, then it crashed” method in describing the bug in the issue tracking tool. Which is not so cool. Invariably the tester will leave out a step they took and the developer will not be able to replicate the bug.

In steps Instruments with Automation. [Quick disclaimer: I still get a few crashes and freezes with this application, however note it’s even younger than the SDK, in regards to iPhone Automation.] Most explanations of how to use Automation for iPhone describe how your QA tester needs to write a javascript file to replicate his actions, which is good once you have already established a base testing for your application, but with mobile development came shorter development life cycles which in turn meant less time to sit down and write out each and every testing script. More likely you hand of the application to the QA tester and he/she will simply sit down and just start touching away on the mobile device in a pattern of which they already have memorized. Here is where Automation slides into the act of testing. What if a tester could simply plug in his device start clicking away at the application and have all his steps recorded in code format, thus when the application crashes or exhibits incorrect behavior all the tester has to do is go to automation, copy the javascript steps Automation recorded in code format, paste them into the bug and bammo the developer has an exact path to replicate the issue. The seas part and the world becomes the testers oyster as the possibilities grow on the entire automation set your tester can develop...quickly.

Note: You cannot record Automation through the iPhone simulator, you must be running the application on the phone to record your steps in Automation.

Let’s look at the steps on how to do this with lots of pretty screen shots.
-Open up Instruments and select Automation



Go to scripts and select "create"



Attach to the target application you want to record your movements in




Click the little record button at the bottom
Monday, September 24, 2012 12:21:41 PM (Central Standard Time, UTC-06:00)  #    Comments [2] - Trackback
Instruments | xCode
# Tuesday, August 28, 2012

In my most recent project I have witnessed the core concept of memory management doesn’t really stick with most people. It’s understandable, if a modern language even deals with memory management it’s generally taken care of with the compiler. In steps the iPhone, which single-handedly puts Objective C on the map. Objective C up to iOS 5 makes you deal with your own memory management.

Apple says, no problem, use Instruments. Not sure about the rest of you, but despite Instruments looking cool, it just comes across like a graph on a cardiac monitor and gives me very little insight as to what exactly is not working with my application, but I definitely know something is wrong because the little memory bar thingy keeps going higher.

Forget all that business, I’m sure Instruments has it’s place, but for nearly all my issues I use cmd-shift-b and zombies. Yeah that’s right, freaking zombies. When you turn on zombies in xCode it keeps and labels the object who is no longer there, and yet one of your objects is trying to access it. Here's the catch xCode gives the object in hexadecimal code. What does that tell me, nothing. Here is how I get around that, I debug the application until I get the approximate area the application crashes. Then I start using

NSLog(@"Hex memory address of my object: %p", object);

This prints out the hex number of the object. I do this with various objects until I find the one that matches the one with the zombie hex address when the application crashes. This means you need to have your NSLog's in prior to crash unless you can work your way around the console (this is a great skill to have, it has saved me lots of time, but is a blog post to itself). An important thing to remember here is the spot in memory changes after every compile and run, so the zombie address you get at the end when the application crashes is not going to be the same for the next compile and run.

As for the cmd-shift-b, it lists nearly if not all the objects I need to release. Much easier right? I’m sure the super hard core people out there will have an exception for this, but to that I’m sure it’s just that...an exception. See screenshot below to learn how I enable zombies and a few other things to help with memory management (make sure you enable “the few other things,” also.) You can get here by going to "Product->Edit Scheme" in xCode 4.3



Tuesday, August 28, 2012 5:46:01 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
memory management | Objective C | xCode
# Wednesday, April 25, 2012




Automatic Reference Counting causes the wonderful ASIHTTPRequest to not work, I suppose one could fix it, since it's on github, but for right now I took the easy route and just turned off Automatic Reference Counting.

Here are the steps:
  • Click on you project, in the left hand organizer.
  • Select your target, in the next column over.
  • Select the Build Settings tab at the top.
  • Scroll down to "Objective-C Automatic Reference Counting" (it may be listed as "CLANG_ENABLE_OBJC_ARC" under the User-Defined settings group),
  • and set it to NO.

Link from Stack Overflow


Wednesday, April 25, 2012 5:07:59 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Objective C | xCode
# Saturday, April 07, 2012




It's easy, so easy, it makes you a tiny bit happy inside once you see how easy it is. I'll post the code then give an explanation for those of you that want more.

CODE:

// create a done view + done button, attach to it a doneClicked action, and place it in a toolbar as an accessory input view...
// Prepare done button

UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
keyboardDoneButtonView.barStyle = UIBarStyleBlack;
keyboardDoneButtonView.translucent = YES;
keyboardDoneButtonView.tintColor = nil;
[keyboardDoneButtonView sizeToFit];

UIBarButtonItem* doneButton    = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(pickerDoneClicked:)];
// I put the spacers in to push the doneButton to the right side of the picker view UIBarButtonItem *spacer1    = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
// I put the spacers in to push the doneButton to the right side of the picker view
UIBarButtonItem *spacer    = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; [keyboardDoneButtonView setItems:[NSArray arrayWithObjects:spacer, spacer1, doneButton, nil]]; // Plug the keyboardDoneButtonView into the text field... self.businessType.inputAccessoryView = keyboardDoneButtonView;
Bam, and you are done.

Explanation:
For nearly every input field (I focus on the UITextField here) in objective-C iOS you can choose one of the core SDK libraries input tools to pop up, whether this is a keyboard or a picker, or one of the many others to choose from. You simply need to assign the input tool to the inputview, but what I stumbled across is Apple so graciously made an additional built in view to give you just a touch more creative flexiblity, it's the inputAccessoryView and it sits on top of the inputView.  All you have to do is stuff another view into the inputAccessoryView. I imagine you could put whatever you want, but a UIToolbar seems to be the unspoken consensus on what to use. Put a few buttons in the UIToolbar and set it as the inputAccessoryView. Done. Yeah. It's not complex, but a nice to have.

Easy enough!



Saturday, April 07, 2012 2:26:23 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Objective C | xCode
# Monday, May 23, 2011


Code:
NSUInteger       newIndex[]   = {0, row};
NSIndexPath	*newPath      = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
There is quite a few things assumed in these 2 simple lines of code. Let's break it down into newbie terms.

First you must understand that a "section" is an area of grouped rows in a tableview. You see this in many iPhone apps. Think about the "Settings" app. Click around in it and you will see sections.

Next you must understand that a tableview assigns the property "cellForRowAtIndexPath" with a NSIndexPath value. In short this property looks at the NSIndexPath's first value for the section the row is in and then the second value for the row itself for the value you are trying to retrieve. 

The 0 in the "newIndex[]" is for the "section" in the tableview, stating this will be the 1st section (in this case the only section). and the "row" is for the...well row in the section within the tableview.

So in the next next line with "*newPath" you have the code assigning the "newIndex" with a "length" of 2. What you are reading here is that tableview should look two nodes deep in your array of sections with each node in your section array caring an array of row nodes (think nested arrays).

The first node is the section array and the second node is the row.
So in our example:
Node 1 = specific node in section array (here its node 0), 
Node 2 = specific node in row array nested in Section array.


If the above is italicized text is confusing see screen shot I attached. The picture may make it easier to understand. Array 0 is the array of section nodes, where each section node contains an array of rows.





An different way to create the NSIndexPath that might be easier to read is to use this function.
Code:
NSIndexPath *myPath = [NSIndexPath indexPathForRow:myRow inSection:mySelction];
Here is the exact definition from Apple Documentation, with the knowledge I gave you above it should be a bit more clear now. A "category" by the way, is, in short, a way to add extra methods to a class without subclassing it.

Many methods of UITableViewDelegate take NSIndexPath objects as parameters and return values. UITableView declares a category on NSIndexPath that enables you to get the represented row index (row property) and section index (section property), and to construct an index path from a given row index and section index (indexPathForRow:inSection: method). Because rows are located within their sections, you usually must evaluate the section index number before you can identify the row by its index number

Monday, May 23, 2011 4:38:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Objective C | xCode
# Sunday, February 27, 2011


Have you ever seen a silk teddy bear. They're nice, soft, smooth and comforting. They take something scary and unmanageable like a grizzly bear, and make the animal manageable, gentle and silky smooth.

In the just-released Beginning iPhone 4 Development, authors Jeff LaMarche and David Mark team up with Jack Nutting to take the ever-growing and changing iOS and break it down into manageable chunks. In this informative and light-hearted read, the authors bring the new edition with updates to key subjects like Core Data, Grand Central Dispatch and iPad/iPod programming specifics. Full of step-by-step instructions and intuitive pictures, Beginning iPhone 4 Development serves as a perfect guide for the novice yet remains effective as a quick reference to the experienced developer. In the end it's all about having fun, making an app you want and not about getting frustrated at trying to understand the idiosyncrasies of iOS. With their latest offering, LaMarche, Mark and Nutting get you on the right path.

Sunday, February 27, 2011 1:33:35 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iphone | iphone | Objective C | readings | xCode
# Sunday, February 13, 2011


Problem:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a UIBarButtonItem that is not in a toolbar or navigation bar already.'

Solution:
You can get the error for a number of reasons, but I'm betting it's because you didn't declare your UIBarButtonItem correctly in either your header file or your implementation file. You might have done something like this in your header file.

@interface TestInterface : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate>
{
    UIButtonItem    *button
}

@property (nonatomic, retain) IBOutlet UIBarButtonItem *Button;


Notice the Button variable is declared with one "B" capitalized and the other "b" is not.

And then in your implementation file you tried to call the button by using the non-capitalized declaration.
Like so:
[poc presentPopoverFramBarButtonItem:button ...];

Explanation:
Usually what causes this is, what I would consider, but technically is not, a syntax error. You tried to call a variable that doesn't exist, kinda. The real kicker is there is no compile error. Which is correct, as you should be able to declare code as such in the header file, it just makes it easy for the user to reference the incorrect variable name.

Sunday, February 13, 2011 11:10:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iPad | Objective C | xCode
# Tuesday, November 23, 2010


Problem:

error: expected '=', ',', ';', 'asm' or '__attribute__' before '>' token

Solution:
You didn't close your "<" or ">" when implementing a protocol. Take a peak, I bet that is it.

Example:
@interface YouRock : UIViewController UITableViewDelegate, UITableViewDataSource>    <-- Notice the missing "<" in front of UITableViewDelegate

Explanation:
Syntax, they are the easiest errors to fix. You should have got this, but guess what I did the same damn thing.

Tuesday, November 23, 2010 8:32:17 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Mac | xCode


You want to know a good Diff application for the Mac. Well you are in luck, there is one bundled with xCode. It's called FileMerge, so you know what to do from here right. No? I'll tell you. Hit that Mother F#cking (apple)command-spacebar to bring up spotlight and type "FileMerge." If you have it, it will show up right at the top. Now hit enter, go on, hit it. Now didn't that feel nice. Welcome to the world of FileMerge.

Coffman out! <-- My tribute to Californication.

Tuesday, November 23, 2010 8:23:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Mac | xCode
# Saturday, September 04, 2010



I'm done! After a summer of surprises, swings, and roadblocks I finally finished this book, a few months behind schedule, but it's done. The last objective-C book I read was by the de facto in Mac OS X development Mr. Hillegass, (my post) I embarked on the journey of reading a book on iPhone development with the man in iPhone teaching Jeff LaMarche. Jeff is every bit as good at breaking down complex topics and making them seem easy as my .Net home skillet Scott Hanselman. In short these dudes are just smart, but they'll never tell you that and they write some good books.

This book is an easy read and provides hands on examples on how to use many of the tools provided with the iPhone SDK 3. The book is spot on with it's examples, but I'm betting new Objective-C users might have trouble following along when  xCode 4 comes out. xCode 4 is quite a bit different graphically than 3 and may render the step by step instructions in this book out of date.

Overall if you are into programming on the iPhone, this is a great book to start, given you have a base working knowledge of Objective-C and an advanced understanding of programming in general.

 

Saturday, September 04, 2010 3:29:55 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iphone | iphone | Objective C | readings | xCode
# Wednesday, September 01, 2010


Error Readout:

error: expected '=', ',', ';', 'asm' or '__attribute__' before 'interface'

Fix:
Added a semicolon.

Explanation:
It's important to remember that this was occurring before the interface tag, which meant it was happening in a file I was importing. In this case it was a header file with an enumeration in it that were not showing an error with a missing semi colon.


Wednesday, September 01, 2010 3:54:31 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iphone | Objective C | xCode
# Sunday, June 06, 2010

When starting a new project you have the ability to  select a template of premade projects. Two examples of this are
    1. Navigation Based Application
    2. View Based application

When these templates are selected xCode will create the appropriate base controller for you in interface builder, such as "Navigation Controller" or a "View Controller" it will also create the appropriate classes for you with some of the most commonly used delegate and datasource methods along with the appropriate methods to override.

With a new project and selecting Window-based application, you are simply creating a blank slate in which you have to create nearly everything. It's rarely advantageous to use this unless, you are creating something outside the templates offered or you are learning how all the pieces fit together.

Sunday, June 06, 2010 7:05:58 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Objective C | xCode
# Sunday, May 09, 2010

The Problem:
I was getting a white screen with no data in a UITableView on it in the iPhone simulator.

The Solution:
I had my initialization code for the array in the the "loadView" method and not the "viewDidLoad" method

Explanation:
Don't read self.view in -loadView. Only set it, don't get it. The self.view property accessor calls -loadView if the view isn't currently loaded. There's your infinite recursion. I'm guessing UITableView calls a View [pretty good guess since "view" is in the name. :)] which in turn caused my recursion.

This was a stupid little error that caused me about 30 minutes of my life due to the fact I didn't get any build errors. A simple copy and paste moved me forward.

Update: I think it might be important to distinguish the differece between loadView and viewDidLoad. (below)

loadView is the method in UIViewController that will actually load up the view and assign it to the "view" property. This is also the location that a subclass of UIViewController would override if you wanted to programatically set up the "view" property. viewDidLoad is the method that is called once the view has been loaded. This is called after loadView is called. It is a place where you can override and insert code that does further initial setup of the view once it has been loaded.

Sunday, May 09, 2010 5:55:43 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iphone | Objective C | xCode
# Tuesday, April 13, 2010

I'll keep this post short. I read this book to prepare myself for iPhone development and give me a deeper understanding of Objective C. This book is probably the best book to start learning Cocoa Programming currently on the market. It gives chapter by chapter examples with exercises to follow along with. The only shortcoming of the book is that it's a bit dated to what the current xCode version is. A few of the examples might take the novice for a spin (which means it took me for a spin, sometimes a quite frustrating spin) because the step by step instructions are not exactly correct due to the fact some of the menu items have changed or been rearranged. Outside of a few minor issues, like the one I mentioned earlier, it's a pretty fun book and I would recommend it to other experienced programmers. Hopefully Mr. Hillegass will come out with a newer version.












Things covered in the book

Memory Management
Target/Actions
Helper Objects
Key-Value Coding; Key-Value Observing
NSArrayController
NSUndoManager
Archiving
Basic Core Data
Nib Files and NSWindowController
User Defaults
Using Notifications
Using Alert Panels
Localization

The list keeps going, it really covers all you need to know for having a strong hold on the basics.

Tuesday, April 13, 2010 9:10:59 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Mac OS X | Objective C | readings | xCode
# Tuesday, March 09, 2010


Error Readout:
error: A valid signing identity matching this profile could not be found in  your keychain

The Problem:

In Keychain Access it reads the error above.

The Solution:

This can be cause by several issues. The highest probability is, you didn't install the certificate you created in the distribution or development page of "certificates" in the iPhone Provisioning Portal.
Tuesday, March 09, 2010 9:37:21 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
App Store | iphone | xCode


Error Readout:
Code Sign error: The identity 'iPhone Distribution' doesn't match any valid certificate/private key pair in the default keychain

The Problem:

I try and build my application and I get the error above

The Solution:
Many things can cause this error. The error is probably caused by one of the steps being done incorrectly in the Program User Guide. Most won't like reading this, but the best way to fix this is to go back and follow, very precisely, the steps in "Program User Guide." In case the link changes you can get to the pdf by going to http://developer.apple.com/iphone, logging in, clicking "iPhone Provisioning Profile" and in the box on the left hand side of the screen titled "Provisioning Resources," you can download the Program User Guide pdf.

Explanation:
Yes, we ALL wish this process could be more streamlined, and require less reading, but it doesn't. If you want to get that app out there, suck it up, read the 60 pages [lots of pictures :) ] and be done with it.
Tuesday, March 09, 2010 9:14:18 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
App Store | iphone | xCode
# Saturday, February 27, 2010
Making an iPhone icon is way easier than I had anticipated. You don't need to round the corners, you don't have to give it the little glow as if the sun is shining down upon it. Simply make your icon in a 57x57 png and the iPhone SDK does the rest for you. Here is a link to some good apple documentation on making an iPhone Icon. See the icon I created below (1) and the icon that showed up once I plugged the image into xcode (2).


1.             2.

     
 

Saturday, February 27, 2010 9:41:41 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
iphone | xCode
Navigation
About the author/Disclaimer
        

My name is Ben Coffman. Currently leading the release of Mobile into Canada for Capital One. I have a strong focus on mobile development, building effective development teams and a drive for rapid prototyping and continuous integration using nearly all SDLCs. When I turn the internet off I focus on my family, random hobbies, and sharing moments in life.

My pseudo provactive thoughts
--> Twitter @coffmanben

Learn About Me
--> Linkedin

Blogs I follow:
  1. Big Nerd Ranch
  2. Jeff Lamarche
  3. Scott Hanselman

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Ben Coffman

Archive
<May 2013>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
All Content © 2013,

Sign In