Posts

Showing posts from December, 2013

Delete all .svn folders in project directory on Mac

In terminal in project directory: find ./ -name ".svn" | xargs rm -Rf  Read here about xargs.

typedef enum in Objective-C

Three things are being declared here: an anonymous enumerated type is declared, ShapeType is being declared a typedef for that anonymous enumeration, and the three names kCircle , kRectangle , and kOblateSpheroid are being declared as integral constants. Let's break that down.  In the simplest case, an enumeration can be declared as     enum tagname { ... }; This declares an enumeration with the tag tagname .  In C and Objective-C (but not C++), any references to this must be preceded with the enum keyword.  For example:     enum tagname x;  // declare x of type 'enum tagname'     tagname x;  // ERROR in C/Objective-C, OK in C++ In order to avoid having to use the enum keyword everywhere, a typedef can be created:     enum tagname { ... };     typedef enum tagname tagname;  // declare 'tagname' as a typedef for 'enum tagname' This can be simplified into one line:     typedef enum tagname { ... } tagname;  // declare both 'enu

Change the name of an iOS app

Image
Go to Targets in Xcode "Build Settings" on your project's targe Search for "Product Name" under "Packaging". Change the value of that what you want the new program name is going to be.

Disable ARC for a single file in a project

Image
It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files. You add compiler flags in Targets -> Build Phases -> Compile Sources . You have to double click on the right column of the row under Compiler Flags . You can also add it to multiple files by holding the cmd button to select the files and then pressing enter to bring up the flag edit box.

Differences between strong and weak in objective-c

A strong reference (which you will use in most cases) means that you want to "own" the object you are referencing with this property/variable. The compiler will take care that any object that you assign to this property will not be destroyed as long as you (or any other object) points to it with a strong reference. Only once you set the property to nil will the object get destroyed (unless one or more other objects also hold a strong reference to it). In contrast, with a weak reference you signify that you don't want to have control over the object's lifetime. The object you are referencing weakly only lives on because at least one other object holds a strong reference to it. Once that is no longer the case, the object gets destroyed and your weak property will automatically get set to nil . The most frequent use cases of weak references in iOS are: delegate properties, which are often referenced weakly to avoid retain cycles, and subviews/control

App Icons on iPad and iPhone

Image
Except for iTunesArtwork , icon files for your app do not need to follow any naming convention. However, each icon file that you include must be listed in the Icon files entry in the Info.plist . Follow the steps in the Adding Icon files in Info.plist section. NOTE:  Icons marked with " Required " must be supplied in your application bundle.  NOTE:  iTunesArtwork icon files should be in png format, but name it without the .png extension. iPhone-only Apps iPhone applications need the following images included as resources in the Xcode project.   iPad-only Apps iPad applications need the following images included as resources in the Xcode project.  Universal Apps   Universal applications need the following images included as resources in the Xcode project.  Adding Icon files in Info.plist To add the Icon files entry you will need to manually edit your Info.plist. Open your Info.plist in Xcode. Command click anywhere in the space below t

Custom fonts in iPhone

Image
Copy your font file into resources Add a key to your Info.plist file called UIAppFonts. ("Fonts provided by application) Make this key an array For each font you have, enter the full name of your font file (including the extension) as items to the UIAppFonts array Save Info.plist Now in your application you can simply call [UIFont fontWithName:@"CustomFontName" size:15] to get the custom font to use with your UILabels and UITextViews , etc…

Convert NSData to NSString

Below example explains how to convert NSData to NSString with Objective-C. using - [ NSString initWithData] function we can convert NSData to NSString. This function returns nil if the encoding is not correct. Syntax of initWithData - ( id )initWithData:( NSData *)data encoding :(NSStringEncoding)encoding; NSString * str =@"Hello"; NSData * data =[str dataUsingEncoding:NSUTF8StringEncoding]; //Data //Convert NSData to NSString NSString * converted =[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"Data =%@",converted);