Xcode에는 Code Sense라는 멋진 소스 인덱싱 툴이 내장되어 있다. 하지만, 소스 편집기로 Emacs 등의 External Editor를 사용한다면 Code Sense는 별로 도움이 되지 않는다. Code Sense 데이터베이스에 접근할 수 있는 툴을 Apple이 만들어 주지 않는한 외부 편집기에서 Code Sense를 활용할 수 있는 방법은 없는 듯 하다.
그래서, 이번에는 GNU GLOBAL이 Objective-C를 대충 해석할 수 있도록 패치를 해 보았다.
원래 GNU GLOBAL은 소스파일을 해석해서 tag를 출력해주는 툴을 아무거나 붙일 수 있도록 되어 있다. 즉, Exuberant Ctags를 사용하여 tagging하고 global을 이용하여 query할 수도 있다는 말이다. 그래서, 처음에는 Objective-C 소스파일에서 tag를 출력해주는 툴을 만들어 GNU GLOBAL에 붙일까 생각했었는데, 귀차니즘이 발동하여 GNU GLOBAL의 C++ 파서를 대충 수정하여 Objective-C tag를 출력하도록 하였다.
한가지 아쉬운 것은 Objective-C 메소드에 대한 reference tag 검색이 안된다는 것. 이건 작업할려다가 포기했다!
아! 실력이 미천하여 버그가 엄청 많이 있을 수 있다!
이 글은 스프링노트에서 작성되었습니다.
UINavigationBar는 tintColor를 이용해서 색상을 바꿀 수 있다. 하지만, 제목이나 버튼의 글자 색깔을 바꾸는 기능은 제공하지 않고 있다. 이건 참 곤란하다. tintColor를 밝은 색으로 주면 제목과 버튼 글자가 잘 보이지 않는다.
비록 정상적인 방법은 아니지만, 글자 색깔을 바꾸어 보았다.
#include <objc/runtime.h>
#include <objc/message.h>
@implementation UIKitHack (UINavigationTextColor)
/*
* -[UINavigationItemView drawText:inRect:]
*
* 이 메소드를 갈아치워서 UINavigationBar의 Title Text Color를 바꿀 수 있다.
*/
static void UINavigationItemView_drawTextInRect(id self, SEL _cmd, NSString *string, CGRect rect)
{
CGPoint point = rect.origin;
UIFont *font = [self performSelector:@selector(_defaultFont)];
/*
* Draw shadow of string
*/
point.y += 2;
[[UIColor whiteColor] set];
[string drawAtPoint:point forWidth:rect.size.width withFont:font lineBreakMode:UILineBreakModeTailTruncation];
/*
* Draw string
*/
point.y -= 1;
[[UIColor blackColor] set];
[string drawAtPoint:point forWidth:rect.size.width withFont:font lineBreakMode:UILineBreakModeTailTruncation];
}
/*
* -[UIButtonLabel textColor]
*
* 이 메소드를 추가하여 Button Text Color를 바꿀 수 있다.
*/
static UIColor *UIButtonLabel_textColor(id self, SEL _cmd)
{
if ([[self superview] isKindOfClass:NSClassFromString(@"UINavigationButton")])
{
return [UIColor blackColor];
}
else
{
struct objc_super super = { self, [UILabel class] };
return objc_msgSendSuper(&super, _cmd);
}
}
/*
* -[UIButtonLabel shadowColor]
*
* 이 메소드를 추가하여 Button Text Shadow Color를 바꿀 수 있다.
*/
static UIColor *UIButtonLabel_shadowColor(id self, SEL _cmd)
{
if ([[self superview] isKindOfClass:NSClassFromString(@"UINavigationButton")])
{
return [UIColor whiteColor];
}
else
{
struct objc_super super = { self, [UILabel class] };
return objc_msgSendSuper(&super, _cmd);
}
}
/*
* -[UIButtonLabel setShadowOffset:]
*
* 이 메소드를 갈아치워서 Button Text Shadow Offset을 바꿀 수 있다.
*/
static IMP UIButtonLabel_original_setShadowOffset;
static void UIButtonLabel_setShadowOffset(id self, SEL _cmd, CGSize offset)
{
if ([[self superview] isKindOfClass:NSClassFromString(@"UINavigationButton")])
{
struct objc_super super = { self, [UILabel class] };
objc_msgSendSuper(&super, _cmd, CGSizeMake(0, 1));
}
else
{
UIButtonLabel_original_setShadowOffset(self, _cmd, offset);
}
}
/*
* 추가하고 갈아치우는 삽질의 마무리
*/
+ (void)load
{
Class class;
Method method;
class = NSClassFromString(@"UINavigationItemView");
if (class)
{
method = class_getInstanceMethod(class, @selector(drawText:inRect:));
if (method)
{
method_setImplementation(method, (IMP)UINavigationItemView_drawTextInRect);
}
else
{
NSLog(@"-[UINavigationItemView drawText:inRect:] method not found");
}
}
else
{
NSLog(@"UINavigationItemView class not found");
}
class = NSClassFromString(@"UIButtonLabel");
if (class)
{
class_addMethod(class, @selector(textColor), (IMP)UIButtonLabel_textColor, "@@:");
class_addMethod(class, @selector(shadowColor), (IMP)UIButtonLabel_shadowColor, "@@:");
method = class_getInstanceMethod(class, @selector(setShadowOffset:));
if (method)
{
UIButtonLabel_original_setShadowOffset = method_setImplementation(method, (IMP)UIButtonLabel_setShadowOffset);
}
else
{
NSLog(@"-[UIButtonLabel setShadowOffset:] method not found");
}
}
else
{
NSLog(@"UIButtonLabel class not found");
}
}
@end
정상적인 방법이 아니므로, 사용 및 응용은 알아서 하시기를...
이 글은 스프링노트에서 작성되었습니다.
Key-Value pair Database Library 중 하나인 Tokyo Cabinet을 한번 써보기 위해 설치해보았다. 설치한 김에 설치 패키지로 만들어 보았다.
참고로 Tokyo Cabinet은 hash table, B+ tree, fixed length array 방식을 지원하는 DBM 스타일의 데이터베이스 라이브러리이다. 자세한 내용은 여기로...
Universal Binary로 빌드하였고, 사용한 컴파일러, 최소 운영체제 버전은 다음과 같이 맞추었다.
| i386 | gcc-4.0 | Mac OS X 10.4 |
| x86_64 | llvm-gcc-4.2 | Mac OS X 10.5 |
| ppc | gcc-4.0 | Mac OS X 10.4 |
| ppc64 | gcc-4.2 | Mac OS X 10.5 |
이 글은 스프링노트에서 작성되었습니다.



global-5.7.6-objc.tar.bz2
TokyoCabinet-1.4.33.pkg.zip