The Xcode 4.3 does not have a simulator other than 5.1 and 4.3, but sometimes we need to test apps on the lower environment. So here is the trick:
You need to have lower Xcode installation files, and copy the simulator folders to Xcode 4.3.
For exemple:
sudo mv /XCode file/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk/ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/
Showing posts with label Mac OS X. Show all posts
Showing posts with label Mac OS X. Show all posts
Jan 4, 2012
(Linux) Couldn't start Apache in Lampp
After upgrading Lampp to the latest version, apache could not be started, the error message is:
/opt/lampp/bin/php: error while loading shared libraries: /opt/lampp/lib/libsybdb.so.5: cannot restore segment prot after reloc: Permission denied
XAMPP: Starting Apache with SSL …
XAMPP: Error 1! Couldn't start Apache!
XAMPP: Starting diagnose…
XAMPP: Sorry, I've no idea what's going wrong.
It needs to disable selinux by using this command:
setenforce 0
/opt/lampp/bin/php: error while loading shared libraries: /opt/lampp/lib/libsybdb.so.5: cannot restore segment prot after reloc: Permission denied
XAMPP: Starting Apache with SSL …
XAMPP: Error 1! Couldn't start Apache!
XAMPP: Starting diagnose…
XAMPP: Sorry, I've no idea what's going wrong.
It needs to disable selinux by using this command:
setenforce 0
Aug 19, 2010
(iPhone)How to customize UIAlertView
First solution is using addSubview which add subviews into an UIAlertView, just don't forget add newlines in the initWithTitle method's message to make sure you have enough space for subviews. Like :
[[UIAlertView alloc] initWithTitle:@"Title" message:@"\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]
But this solution couldn't change UIAlertView's background, here is second solution that creates an UIAlertView's subclass, overrides several methods (setAlertText, alertText, drawRect, layoutSubviews and show), Joris Kluivers made an excellent sample, check it here : CustomAlert
[[UIAlertView alloc] initWithTitle:@"Title" message:@"\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]
But this solution couldn't change UIAlertView's background, here is second solution that creates an UIAlertView's subclass, overrides several methods (setAlertText, alertText, drawRect, layoutSubviews and show), Joris Kluivers made an excellent sample, check it here : CustomAlert
(iPhone)How to customize UINavigationBar's background
UINavigationBar has 2 methods to change it's style, barStyle and tintColor, but neither could set a background image for UINavigationBar.
Here is a solution to do that, add following code in your app delegate implementation file (.m) :
And change the "background_image.png" to the image what you want. This add a category in all UINavationBar used in your application, and you will see a fancy UINavigationBar.
Here is a solution to do that, add following code in your app delegate implementation file (.m) :
@interface UINavigationBar (MyCustomNavBar)
@end
@implementation UINavigationBar (MyCustomNavBar)
- (void) drawRect:(CGRect)rect {
UIImage *barImage = [UIImage imageNamed:@"background_image.png"];
[barImage drawInRect:rect];
}
@endAnd change the "background_image.png" to the image what you want. This add a category in all UINavationBar used in your application, and you will see a fancy UINavigationBar.
Aug 10, 2010
(Objective-C) Objective-C Style Guide
Here are some guides that i found, they are really useful.
Google Objective-C Style Guide
Apple's Cocoa Coding Guidelines
Google Objective-C Style Guide
Apple's Cocoa Coding Guidelines
Jul 28, 2010
(iPhone)How to debug EXC_BAD_ACCESS
In iOS programming, the EXC_BAD_ACCESS happens when application try to access some deallocated objects, but the Debugger Console usually display a simple message of "EXC_BAD_ACCESS", here is an useful solution to track the deallocated object.
- Set NSZombieEnabled = YES. With this argument, console will display a little bit more information, like "method : message sent to deallocated instance ...", sometime we can track the object in the method when it is easy to find.
- Set MallocStackLoggingNoCompact = 1, this argument allow to display alloc history of the object, for example: we got a message "message sent to deallocated instance 0x58448e0", type "info malloc-history 0x58448e0" in the console will display the allocate history of object 0x58448e0, which contains object allocation and deallocation, it is really useful to debug the incorrect release call.
To setup these 2 arguments, you should go to "Project"->"Edit Active Executable project name", add these 2 variables in "Variables to be set in the enviroment", names are "NSZombieEnabled" and "MallocStackLoggingNoCompact", values are "YES" and "1". And check the checkbox to active.
Don't forget remove these variables when you release your application.
- Set NSZombieEnabled = YES. With this argument, console will display a little bit more information, like "method : message sent to deallocated instance ...", sometime we can track the object in the method when it is easy to find.
- Set MallocStackLoggingNoCompact = 1, this argument allow to display alloc history of the object, for example: we got a message "message sent to deallocated instance 0x58448e0", type "info malloc-history 0x58448e0" in the console will display the allocate history of object 0x58448e0, which contains object allocation and deallocation, it is really useful to debug the incorrect release call.
To setup these 2 arguments, you should go to "Project"->"Edit Active Executable project name", add these 2 variables in "Variables to be set in the enviroment", names are "NSZombieEnabled" and "MallocStackLoggingNoCompact", values are "YES" and "1". And check the checkbox to active.
Don't forget remove these variables when you release your application.
Mar 19, 2010
(XCode) How to resolve "Warning: Multiple build commands for output file ..."
Just met a weird warning message in XCode which is "Warning: Multiple build commands for output file ..." after deleting a resource file, and i checked the file does not exist in resource folder any more, finally i found the the file did appear in "targets/app name/copy bundle resources/", than i figure out i accidentally pressed "Delete reference" when i delete the file, and that's why the resource file still exist in the "copy bundle resources" folder
Dec 29, 2009
(Objective-c)How to round a number
Here is a solution to round a float number:
or
Result: 3.142
NSString *pi = @"3.14159265";
int floatSize = 3;
NSDecimalNumber *numericValue = [NSDecimalNumber decimalNumberWithString:pi];
NSDecimalNumberHandler *roundingStyle = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:
NSRoundBankers scale:floatSize raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO
raiseOnDivideByZero:NO];
NSDecimalNumber *roundedNumber = [numericValue decimalNumberByRoundingAccordingToBehavior:
roundingStyle];
or
NSString *pi = @"3.14159265";
NSString *roundedNumber = [[NSString alloc] initWithFormat:@"%.3f",[pi floatValue]];
Result: 3.142
Jul 10, 2009
(Objective-c) How to get MD5 hash string of a NSData
- (NSString*)dataMD5:(NSData*)data {
CC_MD5_CTX md5;
CC_MD5_Init(&md5);
CC_MD5_Update(&md5, [data bytes], [data length]);
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5_Final(digest, &md5);
NSString* s = [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
digest[0], digest[1],
digest[2], digest[3],
digest[4], digest[5],
digest[6], digest[7],
digest[8], digest[9],
digest[10], digest[11],
digest[12], digest[13],
digest[14], digest[15]];
return [s uppercaseString];
}
Mar 24, 2009
(XCode) How to setup a bracket / brace macro in XCode
Before i used XCode and learned Objective-C, i never thought the bracket is a horrible symbol, there is a solution of creating text macro to insert bracket / brace:
1. Open ObjectiveC.xctxtmacro with an text editor, you can find this file with this path:
2.Add follow code in the file:
You can create a similar macro for Brace, here is an example:
Update: In the XCode 3.2 which is released for Snow Leopard, the above lines wouldn't work until add this line in each section:
OnlyAtBOL = YES;
1. Open ObjectiveC.xctxtmacro with an text editor, you can find this file with this path:
/Developer/Applications/Xcode.app/Contents/PlugIns/TextMacros.xctxtmacro/Contents/Resources/ObjectiveC.xctxtmacro 2.Add follow code in the file:
{
Identifier = objc.bracket;
BasedOn = objc;
IsMenuItem = YES;
Name = "Bracket Expression";
TextString = "[<#!expression!#>]";
CompletionPrefix = bra;
},This scope create a text macro "bra" to insert "[<#!expression!#>]", you need to type bra in your code and presse "esc" button, there is a window shows "Bracket Expression", press enter "[<#!expression!#>]" will be inserted.You can create a similar macro for Brace, here is an example:
{
Identifier = objc.brace;
BasedOn = objc;
IsMenuItem = YES;
Name = "Brace Expression";
TextString = "{<#!expression!#>}";
CompletionPrefix = bra;
},Here you have a same text macro "bra" to choose bracket or brace.Update: In the XCode 3.2 which is released for Snow Leopard, the above lines wouldn't work until add this line in each section:
OnlyAtBOL = YES;
Feb 13, 2009
(Objective-C) How to sort an array
Here is an example to sort an array:
- (NSArray *) sortArray:(NSArray *)array :(BOOL)inAscending {
if (inAscending) {
return [array sortedArrayUsingSelector:@selector(compare:)];
}
else {
NSArray *ascendArray = [array sortedArrayUsingSelector:@selector(compare:)];
return [[ascendArray reverseObjectEnumerator] allObjects];
}
}
Oct 20, 2008
(Linux, Mac OS X) How to get the memory alloc history
There is a good debug tool in Linux and Mac which is gdb, it has a useful command to show the history of a memory allocation.
(gdb) shell malloc_history 2417(processId) 0x35d4f0(memoryAddress)
(gdb) shell malloc_history 2417(processId) 0x35d4f0(memoryAddress)
Oct 7, 2008
(Mac OS X) How to resolve the problem that menu bar items disappear after login
It's the first time i met this problem on Mac, all my menu bar items disappeared after login. I found a solution to resolve this, delete
Users/yourname/Library/Preferences/com.apple.systemuiserver.plist then log out and back in or just a simple restart your Mac.
Users/yourname/Library/Preferences/com.apple.systemuiserver.plist then log out and back in or just a simple restart your Mac.
Subscribe to:
Posts (Atom)