Skip to content

Objective-C

Objective-C Classes (list)

  • NSAffineTransform
  • NSArchiver
  • NSArray
  • NSAssertionHandler
  • NSAttributedString
  • NSAutoreleasePool
  • NSBundle
  • NSCachedURLResponse
  • NSCalendarDate
  • NSCharacterSet
  • NSClassDescription
  • NSCoder
  • NSCondition
  • NSConditionLock
  • NSConnection
  • NSCountedSet
  • NSData
  • NSDate
  • NSDateFormatter
  • NSDecimalNumber
  • NSDecimalNumberHandler
  • NSDeserializer
  • NSDictionary
  • NSDirectoryEnumerator
  • NSDistantObject
  • NSDistributedLock
  • NSDistributedNotificationCenter
  • NSEnumerator
  • NSError
  • NSException
  • NSFileHandle
  • NSFileManager
  • NSFormatter
  • NSHTTPCookie
  • NSHTTPCookieStorage
  • NSHTTPURLResponse
  • NSHashTable
  • NSHost
  • NSIndexPath
  • NSIndexSet
  • NSInputStream
  • NSInvocation
  • NSKeyedArchiver
  • NSKeyedUnarchiver
  • NSLock
  • NSMapTable
  • NSMessagePort
  • NSMessagePortNameServer
  • NSMethodSignature
  • NSMutableArray
  • NSMutableAttributedString
  • NSMutableCharacterSet
  • NSMutableData
  • NSMutableDictionary
  • NSMutableIndexSet
  • NSMutableSet
  • NSMutableString
  • NSMutableURLRequest
  • NSNetService
  • NSNetServiceBrowser
  • NSNotification
  • NSNotificationCenter
  • NSNotificationQueue
  • NSNull
  • NSNumber
  • NSNumberFormatter
  • NSObject
  • NSOutputStream
  • NSPipe
  • NSPointerArray
  • NSPointerFunctions
  • NSPort
  • NSPortCoder
  • NSPortMessage
  • NSPortNameServer
  • NSProcessInfo
  • NSPropertyListSerialization
  • NSProtocolChecker
  • NSProxy
  • NSRecursiveLock
  • NSRegularExpression
  • NSRunLoop
  • NSScanner
  • NSSerializer
  • NSSet
  • NSSocketPort
  • NSSocketPortNameServer
  • NSStream
  • NSString
  • NSTask
  • NSThread
  • NSTimeZone
  • NSTimeZoneDetail
  • NSTimer
  • NSURL
  • NSURLAuthenticationChallenge
  • NSURLCache
  • NSURLConnection
  • NSURLCredential
  • NSURLCredentialStorage
  • NSURLDownload
  • NSURLHandle
  • NSURLProtectionSpace
  • NSURLProtocol
  • NSURLRequest
  • NSURLResponse
  • NSUnarchiver
  • NSUndoManager
  • NSUserDefaults
  • NSValue
  • NSValueTransformer
  • NSXMLDTD
  • NSXMLDTDNode
  • NSXMLDocument
  • NSXMLElement
  • NSXMLNode
  • NSXMLParser
  • NXConstantString

오브젝티브-C (Objective-C, 종종 ObjC로 표기) 언어는 C 프로그래밍 언어에 스몰토크 스타일의 메시지 구문을 추가한 객체 지향 언어이다.

현재, 이 언어는 애플의 매킨토시의 운영 체제인 맥 오에스 텐과 아이폰의 운영 체제인 iOS에서 사용되고 있다. 오브젝티브-C는 애플의 코코아를 사용하기 위한 기본 언어이며, 원래는 넥스트의 NeXTSTEP 운영 체제에서 주 언어였다. 일반적인(Generic) 오브젝티브-C는 앞에서 언급한 라이브러리를 사용하지 않는다.

Basic

List of Objective-C 2.0 @ Compiler Directives

  • @class
  • @defs
  • @protocol @required @optional @end
  • @interface @public @package @protected @private @property @end
  • @implementation @synthesize @dynamic @end
  • @throw @try @catch @finally
  • @synchronized @autoreleasepool
  • @selector @encode
  • @compatibility_alias
  • @"string"

CMake compile

clang을 사용할 경우 아래와 같이 objective-c를 컴파일 할 수 있다.

cmake_minimum_required(VERSION 2.8)
project(HelloWorld)
set(NAME HelloWorld) 
set(CMAKE_C_FLAGS "-x objective-c")
#set(CMAKE_CXX_FLAGS "-x objective-c++")

set(HEADER_FILES 
    ./uhdplayerengine/HelloWorld/HelloWorld/AppDelegate.h
)
set(SOURCE_FILES 
    ./uhdplayerengine/HelloWorld/HelloWorld/AppDelegate.m
    ./uhdplayerengine/HelloWorld/HelloWorld/main.m
)
set(XIB_FILE
    ./uhdplayerengine/HelloWorld/HelloWorld/Base.lproj/MainMenu.xib
)

add_executable(
    ${NAME}
    MACOSX_BUNDLE
    ${HEADER_FILES}
    ${SOURCE_FILES}
    ${XIB_FILE}
)

set_source_files_properties(
    ${XIB_FILE}
    PROPERTIES
    MACOSX_PACKAGE_LOCATION
    Resources
)

set_target_properties(
    ${NAME}
    PROPERTIES
    MACOSX_BUNDLE_INFO_PLIST
    ./uhdplayerengine/HelloWorld/HelloWorld/HelloWorld-Info.plist
)

target_link_libraries(${NAME}
    "-framework Cocoa"
    "-framework AppKit"
    "-framework CoreData"
    "-framework Foundation"
)

Linker플래그를 전달 할 때 Foundation-lFoundation으로 인식할 경우 -Wl,-framework,Foundation과 같이 전달하면 된다.

Framework

  • Foundation
  • AVFoundation
  • CoreVideo
  • CoreMedia
  • CoreGraphics
  • OpenGL
  • CoreImage
  • AppKit
  • CoreFoundation
  • Security
  • AudioToolbox
  • VideoToolbox
  • CoreServices
  • CGDirectDisplay

Memory management

Objective-C의 메모리 관리 방법에 대한 설명.

Memory management: Favorite site

Examples

문자열 포맷팅

NSString 클래스의 stringWithFormat 함수 사용.

int i = 1;
NSString *name = @"thefirstsong";
NSString *filename = [NSString stringWithFormat:@"%0d-%@.mp3", i, name];

NSStringCFStringRef 상호 변환

Typically:

NSString *yourFriendlyNSString = (__bridge NSString *)yourFriendlyCFString;

and

CFStringRef yourFriendlyCFString = (__bridge CFStringRef)yourFriendlyNSString;

Now, if you want to know why the __bridge keyword is there, you can refer to the Apple documentation. There you will find:

  • __bridge transfers a pointer between Objective-C and Core Foundation with no transfer of ownership.
  • __bridge_retained or CFBridgingRetain casts an Objective-C pointer to a Core Foundation pointer and also transfers ownership to you. You are responsible for calling CFRelease or a related function to relinquish ownership of the object.
  • __bridge_transfer or CFBridgingRelease moves a non-Objective-C pointer to Objective-C and also transfers ownership to ARC. ARC is responsible for relinquishing ownership of the object.
NSStringCFString

:

// Don't transfer ownership. You won't have to call `CFRelease`
CFStringRef str = (__bridge CFStringRef)string;

// Transfer ownership (i.e. get ARC out of the way). The object is now yours and you must call `CFRelease` when you're done with it
CFStringRef str = (__bridge_retained CFStringRef)string // you will have to call `CFRelease`
CFStringNSString

:

// Don't transfer ownership. ARC stays out of the way, and you must call `CFRelease` on `str` if appropriate (depending on how the `CFString` was created)
NSString *string = (__bridge NSString *)str;

// Transfer ownership to ARC. ARC kicks in and it's now in charge of releasing the string object. You won't have to explicitly call `CFRelease` on `str`
NSString *string = (__bridge_transfer NSString *)str;

CFString to C string

const char *cs = CFStringGetCStringPtr( cfString, kCFStringEncodingMacRoman ) ;
puts( cs ) ; // works

Sample

MotionSensorManager (Geosoft iOS MyCarNavi)
MotionSensorManager.zip
iPhone의 모션센서 데이터 취득 클래스.

See also

Favorite site

References


  1. Wireframe_-_Objective-C_Memory_management.pdf 

  2. Closure_and_anonymous_functions_in_Objective-C.pdf 

  3. Apple-objective-c.pdf 

  4. Cpp-objc-en.pdf