BetaDesigns( Blog ) Flex and Component Development

10Jul/100

Converting MX Component to Spark Component ( Part 2 – a )

In the previous post we began building our custom Spark colorPicker by creating the preview class and it's corresponding default skin.
In this post we will begin by creating a KeyboardManager class that will allow us to calculate the new index in the dataProvider after a Up/Down/Left/Right keyboard input.

This class can become quite complicated because we want the following behaviour from our keyboard manager.
The selected index should be able to move up past the top of the dataProvider and move to the bottom row and vice versa, in addition we should be able to go off the left hand side of the columns and appear on the right hand side and vice versa.

For example if the dataProvider has 25 items and each row contains 5 columns.

Up / Down Examples.
If we are at column 1 row 1 ( box 1 ) and we press up we should go to column 1 row 5( box 2 ) and then for every key press we should move up the column until we hit the row 1 column 1 index again. However if we press down then we should go to column 1 row 2 and so forth until we hit column 1 row 5 ( box 2 ). Then when we press down again we should move to the top of the column again row 1 column 1 ( box 1 ) and this should be the case for each column no matter how many rows it has.

Box 1          Box 2
Box oneBox two

10Jul/100

Useful Xcode breakpoints for debugging

Just a quick list of the most useful breakpoints I have found for debugging purposes. This is more of a personal reference so that I can add them back to any new install of Xcode.

objc_exception_throw
[NSException raise]
malloc_error_break

In addition here is a great tech paper on debugging in xcode called Mac OS X Debugging Magic

And here is a nice tutorial for using instruments to debug

3Jul/100

Custom XCode Logger

I came across this method for creating a Debug Logger for XCode projects.
Basically you create a macro that says only process this piece of code if we are running in debug mode. This allows you to create logging throughout your application without having to worry about removing it before you do a release build as it won't be included in the release code.

To begin you need to add a GCC_PREPROCESSOR_DEFINITIONS | DEBUG=1 to your projects TARGET>Get Info>BUILD settings.

Next go into YOUR_APPLICATION_NAME_Prefix.pch file ( located under Other Sources ) and place the following macro.

 
#ifdef DEBUG
# define trace(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define trace(...)
#endif
 

This will create a custom Logger that can be used in the same way as NSLog except that it will output a more descriptive message showing the location and line number of where the log item is located.
edit: I have cheekily renamed it to trace();

 
trace( @" Does my debug tracer appear in production code?  %@",
@"NO!"  );