2014年7月29日 星期二

[Xcode] Fixed: Build error that it import Objective-C codes in the .cpp?

Build error: (NSObjCRuntime.h & NSObject)

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:371:1: Expected unqualified-id

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:373:19: Unknown type name 'NSString'
...

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/objc/NSObject.h:11:1: Expected unqualified-id
...


[Solution]
rename extension name from .cpp into .mm

[Xcode] Fixed: _CMAudioFormatDescriptionGetStreamBasicDescription", referenced from: -[captureNSObject init] in captureNSObject.o

I have a project to build some code,  and then it has error in the follow:

Undefined symbols for architecture x86_64:
  "_CMAudioFormatDescriptionGetStreamBasicDescription", referenced from:
      -[captureNSObject init] in captureNSObject.o
  "_CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer", referenced from:
      -[captureNSObject captureOutput:didOutputSampleBuffer:fromConnection:] in captureNSObject.o
  "_CMSampleBufferGetNumSamples", referenced from:
      -[captureNSObject captureOutput:didOutputSampleBuffer:fromConnection:] in captureNSObject.o
ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

[Solution]
Add CoreMedia.framework into "Linked Frameworks and Libraries".

2014年7月24日 星期四

[Xcode] Enable/disable a button

@property (retain, nonatomic) IBOutlet UIButton *btnButton;
enable/disable like this in .m file:
btnButton.enabled = NO; // disable button
btnButton.enabled = YES; // enable button

2014年7月16日 星期三

[Xcode] How to quit the application when the window closes

If you want an application to quit (terminate) when the window is closed, you can do this:

-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)theApplication
{
    return YES;
}

2014年7月14日 星期一

[Xcode] How to convert between NSTextField and NSString

// NSString --> NSTextField
NSTextField * txtField = [[NSTextField alloc] init];
NSString *str = @“1234”;
txtField.stringValue = str;

// NSTextField --> NSString
NSString *str1 = txtField.stringValue;

[Xcode] How to convert byte array to NSString

Byte* btData = new Byte[12];
memset(btData, 0, sizeof(Byte) * 12);
...

NSData *data = [NSData dataWithBytes:btData length:sizeof(btData)];
NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

2014年7月2日 星期三

[Xcode] Hotkey

command + X
- cut

command + C
- copy

command  + V
- paste

command + A
- select all

command + /
- add/remove comment

command + \
- add/remove breakpoint

command + R
- run

command + B
- build

command + F
- find

shift + command + F
- find in project

command + option + F
- find and replace

shift + command + option + F
- find and replace in project