2010
02.26
A problem: given an object a of class A that aggregates a publicly accessible instance of class B determine if an instance changed by polling periodically. This comes up often in concurrent systems where an object change warrants a response while KVO is undesirable. The first thought that comes to mind is to a cache the instance of B during each cycle of polling after the comparison of the cached instance to the present value.
Our code might look like this
if (cachedB != [a valueOfB]) { triggerEvent(...); }
cachedB = [a valueOfB];
Unfortunately this fails miserable due to the fact that a newly allocated instance of B may occupy the same memory location as the previous one (assuming, of course, that we never retain the cached value). This is a low probability failure and is extremely hard to debug. This bug is solved by storing a timestamp upon change of instance of B inside a, and cacheing it instead of the memory address.
Category Cocoa, Programming |
2010
02.24
Authentic joy is everlasting
A thing that freely permeates
As born in hearts of lovers lusting
So nascent is when we create
It hides itself in child’s smile
In ray-ing clouds of sunrise
It so resides in every shining
Of every memorable time
Category Poetry |
2010
02.09
Leopard and (Sno) have a new way of specifying deployment location of a dynamic lib. Follow this link for an in depth explanation.
Category Uncategorized |
2010
02.09
A nifty command python -m SimpleHTTPServer will start serving the current directory on port 8000. Seems like a cute alternative to broken iChat transfers… found it here among other cute Linux miscellanea.
When in doubt about missing symbols during linking nm <filename> can be an invaluable asset. When struggling with questions about architectures of a binary otool -vf <filename> is the there to help.
Category Cocoa |
2009
09.01
If ever in need to examine a view hierarchy at runtime HTViewHierarchy is your friend. It is a superb reverse engineering tool. F-Script can be used to this end to a degree, but sometimes one just needs a hierarchy browser.
Category Cocoa, Uncategorized |
2009
05.20
There times when standard locations for libraries and frameworks just don’t cut it. For such times a lineup of environment variables can be used to guide the linker. Typing
in the terminal tells the story. Also
otool -L <executable-name>
lists library locations for a given executable.
Category Cocoa, Programming, Uncategorized |
2009
04.29

Not an exercise for the faint of heart. In fact this applies to using it in your programs as well. While I managed to build the libs, I never managed to build the demos that rely on Qt.
Download the mac distribution from CGAL portal.
Prior to installing CGAL you need to have a few prerequisites on your system: boost, GMP, MPFR, Qt (3 didn’t manage to get it working with 4)
It is easiest to use macports to get these. After downloading and installing macports install the libraries as follows
sudo port install boost
sudo port install GMP
sudo port install MPFR
sudo port install qt3-mac
You may also wish to install qt4 by invoking
sudo port install qt4-mac-devel
Open your terminal window and cd to CGAL home directory
Copy (rename) boost program_options library file so the installer picks it up by going into /opt/local/lib and type
cp libboost_program_options-mt.a libboost_program_options.a
Invoke ./instal_cgal -i to enter interactive mode of their installer
Provide the paths the installer cannot find automatically (they are all in /opt/local/include and /opt/local/lib)
Before building examples (from examples directory invoke make) don’t forget to set an environment varible
export CGAL_MAKEFILE=<path_to_CGAL-3.3.1>/make/makefile_i386_Darwin-9.6_g++-4.0.1
Tags: AAAdd new tag Category Cocoa, Programming |
2009
04.13
Backporting LogKit to Tiger proved to be a pain in the neck. Crossdevelopment is tedious and the macros-riddled code looks ugly. On the upside I fixed a few bugs and reorganized the projects. The current release SymbicLogKit 0.92 is tested under both Tiger (10.4.11) and Leopard and includes source for both the framework and examples.
To include SymbicLogKit in your own projects follow these steps:
- Add SymbicLogKit as a dependent project to your project.
- SymbicLogKit is built as a private framework so you will need to add a “Copy” stage to your target to place SymbicLogKit into a Frameworks subdirectory of your build product.
- Make your target dependent on the principal target of SymbicLogKit project.
- Now we need to tell the compiler where to look for the SymbicLogKit.framework since it isn’t available for inclusion in the project (it doesn’t exist yet). Modify Framework Search Paths setting in your build settings per configuration to point to the appropriate directory relative, for instance, to your project location e.g. $(PROJECT_DIR)/../SymbicLogKit/build/Release.
- Since the framework isn’t available for inclusion in our host project we will be weak-linking to it. Locate Other Linker Flags in you build settings and set it or augment it to include -weak_framework SymbicLogKit -framework SymbicLogKit
- You may want to uncheck Build Active Architecture Only build setting.
Category Cocoa |
2009
04.07
In Leopard one can obtain the a terminal without enabling the root account. Just type “sudo su” and provide your user password. Seems like a cleaner way to operate as root.
Category Cocoa |
2009
02.20
At last releasing SymbicLogKit. The kit is a simple logging/tracing framework polarized toward desktop (vs. server) development; an itch I’ve needed to scratch for quiet some time. I can already hear a poignant skeptic say that printf and NSLog do the job just fine, and that availability of other solutions such as Log4Coocoa and ASL (Apple System Logging) adds the insult to an injury.
I was not entirely happy with the existing solutions and the following points and decided to build my own framework.
- Tracing/logging/debugging code often serves a purpose long after its initial purpose, so it shouldn’t be removed much of the time following a debugging session. Instead logging code should be well thought out as to provide a developer with useful info in the future.
- If the above statement is accepted then we need a means of selectively blocking/enabling tracing code based on origin, level, thread, and other parameters. Without the ability to select what gets through we’ll simply get lost in the overly verbose output.
- Enabling/disabling parts of output should be snappy and should be done at runtime.
- A developer may want to do more useful things than
printf with tracing output, so the output should be structured.
- The framework should be UI centric, nice to look at, and should be easy to include and take advantage of in desktop applications.
The core of the framework is a singleton class called SYLogger. The instance of this class allows a user to add objects conforming to SYLoggerChannel protocol. Such objects are essentially output channels for a logger instance. There are two such objects provided by the framework: SYConsoleView and NSLoggingChannel.
SYConsoleView is an NSView that can be embedded into your application much the same way as any NSView subclass. The view is a tabular console for your output. On the other hand NSLoggingChannel is a simplistic channel that forwards your output to NSLog(...) call having formatted it nicely.
In order to make use of the framework the channels must be added to SYLogger instance. Messages are sent to the logger by invoking one of the following macros. There are 4 debugging levels defined at the moment (Debug, Info, Warning, Error) each assigning an immediacy level to a message. The variadic macros take NSString*s as parameters, the first being a format string (think [NSString stringWithFormat:...]).
#define elog(str, ...)
#define elogDebug(str, ...)
#define elogInfo(str, ...)
#define elogWarn(str, ...)
#define elogError(str, ...)
There’s also an SYConfiguratorView which enables a user (a developer typically) to configure the logger. By configure I mean to provide a list of class-selector-level tripples describing which output should be blocked. The control is nothing more than a table with the first column hosting an ICU regular expression for class-name, the second hosting an ICU regular expression for selector-name (e.g. “dictionaryWithObjects:forKeys:count:”, “array”, etc.).

The above screenshot, for example, represents a configuration that blocks output from within drawRect: selectors of all classes whose names end in “View” as well as from all selectors whose name begins in “run” irrespective of a class they belong to.
Category Cocoa, Programming |