Archive for the ‘Mac’ Category

Whether to call [super mouseDown:] etc or not

From View Programming Guide : Handling Mouse Click and Dragging Events

Notice that the mouseDown: implementation in Listing 4-7 does not call the super implementation. The NSView class’s default implementation for the mouse handling events are inherited from NSResponder and pass the event up the responder chain for handling, bypassing the view in question entirely. Typically a custom NSView subclass should not call the super implementation of any of the mouse-event methods.

Once [super mouseDown:…] is called, mouseDragged: is not called. mouseMoved: can be still received by calling [[self window] setAcceptsMouseMovedEvents:YES]; though.

So, for custom views which needs to handle all details of mouse event, it’s better not to call super’s messages of NSResponder, in other words, mouseDown, mouseUp, mouseDragged, mouseMoved, etc.

There is different results obtained by different combination of acceptsFirstResponder, acceptsFirstMouse etc. So, when implementing mouse event handler, please consider situation thoroughly and test as many as cases you can imagine. ( Hmmmm… S/W engineers who are not considerate tend to think that they know everything and ignore general situation.. So, I wonder if this recommendation would be effective to them. )

Without creating help files using Doxygen/HeaderDoc, Xcode 5에선 자동으로 Quick Help에 코멘트를 보여줍니다.

“structured comments in your own source code are displayed in the quick help panel and in code completion popover views. Doxygen and HeaderDoc structured comments are supported formats.”

Concurrent programming in OpenCL vs Grand Central Dispatch

converting frame image data in CVImageBufferRef to PNG

This StackOverflow explains how to convert a video frame image in CVImageBufferRef to PNG through CIImage of Core Image and CGImageRef of Core Graphics.
Of course, it can be also changed to NSImage and do whatever you want there too.
(toll-free bridging between Core* and NS*.. :). But in this case, there are some more chores to do manually. )

Be careful about object ownership around NSOperation and NSOperationQueue

For recent years, Apple people concentrated more on iOS than Mac OS X.
So, during that period of time, I’ve noticed that the quality of SDK for OS X and its documentation got worse.

In the case of NSOperation and NSOperationQueue, actually it was announced before the iOS was announced as far as I remember.
However, at that time, they were implemented around pthread or NSThread to provide eaiser pattern for multithreaded programming under specific scenario. ( Although those serial and pipe-like working model is quite convenient in many circumstances, but not always still. If you need more sophisticated interaction among threads, etc, you still need implementation with pthread/NSThread. )

Here is one example.
Were they clear about object ownership for NSOperation ( and its child classes ) when it’s added into a queue?
For tasks like it’s just queued and quickly consumed and gone, it will not easy to catch a case where an instance of a concrete children classes of NSOperation is deallocated while it’s in a queue and being processed.

However, today I did noticed such a case. So, be careful about this thing.
Making a pattern around something looks cool. It may show yourself a very skillful developer. By glancing at that kind of code, people can think of you as such.
However, it’s only skin-deep.

OperationQueue, Operation and ownership

ADDED : According to the document of NSOperationQueue, it says for addOperation:

The operation object to be added to the queue. In memory-managed applications, this object is retained by the operation queue. In garbage-collected applications, the queue strongly references the operation object.

So, at least it’s said to retain the operation. But be careful about it.

When calling boost methods causes EXC_BAD_ACCESS ( boost from Mac Port)

I ran into a weird problem.
Whatever simple boost method I call, it raised EXC_BAD_ACCESS exception. So, I tried to make a really short and simple project with which I can focus on this boost issue other than any other issues.

Why boost crashes

( Hmm.. when was my last time to use “target” instead of creating a sub project for having multiple projects under one project/workspace file? They have their own use, but for flexibility of using projects in other projects, “projects” looks better than “target”, but “target” has its own use. )

As we know, LLVM uses libc++ instead of libstdc++. So, if you create an C++/Objective-C++ project, it will use libc++ by default.

However, let’s take a look at what libraries boost libraries depend on. ( Boost is usually called header-only library. But there are ‘libraries’, really. )

JongAms-MacBookPro:lib jongp$ otool -L libboost_system-mt.dylib
/opt/local/lib/libboost_system-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
JongAms-MacBookPro:lib jongp$ otool -L libboost_filesystem-mt.dylib
/opt/local/lib/libboost_filesystem-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/local/lib/libboost_system-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
JongAms-MacBookPro:lib jongp$

So, those boost libaries depends on libstdc++ not libc++.

Now, you have a clue.
If you change the C++ standard library to use from libc++ to libstdc++, it will not have the problem.

Finally.. it’s coming!!!!! Beyond Compare for Mac!!!

This is my favorite compare & merge tool since early 1990’s.It had the most intelligent comparison algorithm allowing shifted code block matching. It showed differences within a line also.

Now, finally it is coming to Mac.
Don’t need to rely on Apple’s merge tool, which can’t handle sophisticated situation or any other comparison tool available on Mac!

Let’s try!

%d bloggers like this: