Search Posts in my Blog

Wednesday 25 July 2012

iPhone Interview Questions and Answers



1. What is @interface?

- It’s a keyword used to declare the Class.





2. What is @implementation?

- It’s a keyword used to define the Class.





3. Garbage collector in iPhone?

- iOS 5.0 has got the ARC ( Automated reference counting ).  Objective C does not have a garbage collector rather it uses the reference counting algorithm to manage the memory. This was the developers task until Apple launched iOS 5.0. Again if you are targeting iOS 4.0 or earlier , ARC is no more a choice for you .



4. What is delegate?

- Delegate is an object that handles the events happening on an object. To do that delegate has to follow a protocol specifying the task it is going to handle .





5. What is @synthesize?

- We use @synthesize to generate getters and setters automatically from compiler. We declare properties and then generate getter and setter method by using @synthesize.





6. What are the features of iOS 5.0 ?

- https://developer.apple.com/technologies/ios5/





7. What is nonatomic ?

- nonatomic and atomic are related to multithreading environment .

 - If a property has an attribute as “nonatomic” that means multiple threads can modify that property concurrently.

- If the attribute is “atomic”, the threads would be given access atomically.

-  So “Atomic” is thread safe while “nonatomic” is thread unsafe.

- Atomic drastically hampers the performance so until and unless not needed you should never go for atomic attribute. ‘nonatomic ’ will do in most of the cases.





8. What are the delegate methods of MKMapView ?

- Check the MKMapViewDelegate in the Documentation. If you don’t have Xcode with you then search on Google.





9. What are the important delegate methods of NSXML parser?



-DidStartElement

-FoundCharecters

-DidEndElement

-FoundError







10. What is @dynamic and any place where it is used ?

- It tells compiler that getter and setter are not implemented by the class but by some other class .

- May be super class or child class .



Example – Core Data

-       The Managed object classes have properties defined by using @dynamic.





11. What is @property?

- It is a keyword used to declare a property.



12. What is data source?

- The datasource is an object that implements the required datasource protocol that is needed to create a complex control.

Ex UITableView is a view that needs a datasource object to which will help building the table. Often it’s the controller that is displaying the table view. The protocol that dataSource object ( mostly controller it self) has to implement is “UITableViewDataSource” .



13. What is model view controller?

- MVC is a Design pattern .

Model stands for the database  object which will manage all the database transaction .

- View stands for the UI i.e. the UI visible to the user. User will be interacting with the view.

- Controller is an object who handles the view events and also render the database changes to the UI. In short , it bridges the interaction between Modal and View.







14. what is @ protocol?

- @protocol is a keyword used to define a protocol. A protocol is a set of method declarations defining specific purpose. It only lists out the methods prototype , the actual implantation would be provided by the class that implements /  follows the protocol.





15. what is id?

- id is a generic reference type. The variable declared using id data-type can hold any object. Most of the methods that returns an object has ‘id’ as return type. Ex – init.



16. Explain memory management?

- Most of the object oriented languages have the Garbage Collector .  All the objects are allocated on the heap memory. The Garbage Collector is a thread that runs periodically to check all the objects, which are no more being referenced from the program. Garbage collector then de-allocates all these unreferenced objects on the Heap. In this environment programmer does not need to worry about de-allocating the objects explicitly.



In Objective – C we don’t have garbage collector. ( Note: Its available from iOS 5.0 only). So in this environment we have to explicitly take care of allocation and deallocation of all the objects in our program.  And to manage this Objective C uses ‘reference counting’ algorithm as the memory management algorithm. 



Reference Counting: In this algorithm every object keeps track of it owners ( I,e reference variables from the program ) . No of owners is represented by the property retainCount declared in NSObject. If this retainCount goes to ‘0’ the object gets deallocated automatically.  We never call dealloc method on any object explicitly.





17. what is retain and release?

- retain and release are two method defined in NSObject . - -

- These methods are related to Memory Mangement .

- retain method when called increases the retainCount by 1.

- release method when called decreases the retainCount by 1





18. what is dealloc?

- dealloc method is called on an object to actually deallocate the memory for that object. ( We should never call dealloc directly )

- In reference counting environment when retainCount of an object reaches to ‘0’, the dealloc method is called on that object automatically to delete the memory space of the object .

- If the object is having some reference type variable holding other objects, then we should call release method on every variable in dealloc.

- If you override then [super dealloc] should be the last line in this method.





19. What is Autorelease pool?

-  Autorelease pool is like a container that holds the autoreleased objects .

- This pool is drained with every run-loop of the Application

- When the pool gets drained, autorelease pool sends a release message to all the objects it was holding.







20. What is Foundation Framework? Can you explain some classes from that?

- Foundation is one of the important frameworks in COCOA Touch.

- It contains the classes like  NSArray , NSString , NSObject etc .





21. What is the difference between NSArray and NSMutableArray?



* NSArray

-        is a static array

-       Once created you can not modify the array

-       Ex you can not add or remove the object in NSArray.



* NSMutableArray

-       is a dynamic array

-       You can add or remove the object dynamically.





22. Write a delegate method of the table view?

 - (void)tableView:( UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath





23. What are the delegate methods of NSURLConection?

- didReceiveResponse:

- didReceiveData:

- didFinishLoadingData:

- didFailWithError:





24. What is cocoa ?

- COCOA is a collection of frameworks used to write Applications for MAC OS X.





25. Singleton classes

- A singleton class is such a class from which no more that one instance can be created. So there will always be single instance created throughout the program.

Ex UIApplication.

UIAlertView Changes in iOS 5



The UIAlertView class has been available since iOS 2. It is similar to the UIActionSheet class but generally the UIAlertView is used to display an alert message to the user whereas UIActionSheet is useful when you want the user to confirm or choose between a set of options. This post will look at some useful additions to UIAlertView in iOS 5 however that also permit the user to enter some text into the alert view.

The Default Style

Before we look at what has changed in iOS 5 it is probably worth a quick recap of how UIAlertView worked in iOS 4. In all of these examples I will use an alert view with two buttons, a cancel button and an OK button. The code to create and show a basic UIAlertView is as follows:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"DefaultStyle"
                           message:@"the default alert view style"
                           delegate:self
                           cancelButtonTitle:@"Cancel"
                           otherButtonTitles:@"OK", nil]; 
[alertView show];
The initialiser is fairly self-explanatory, it takes a title and a longer description text message which is displayed in the body of the alert view. The delegate is optional and for simple alerts can be set to nil. As I will show in a moment the delegate is required if you want to interact with the alert view for example to find out which button the user pressed.
The cancelButtonTitle may be nil if you do not want a cancel button otherwise it is set to the text to display in the cancel button. Finally there is a nil-terminated list of titles for additional buttons to show in the alert. In this case we just add an OK button. The appearance of the alert view is shown below:
The view is dismissed by pressing either the Cancel or OK buttons. If you want to know which button the user pressed you need to implement some methods from the UIAlertViewDelegate. First we make our view controller adopt the delegate protocol:
@interface UYLViewController : UIViewController <UIAlertViewDelegate>
Then in the view controller we implement alertView:didDismissWithButtonIndex as follows:
- (void)alertView:(UIAlertView *)alertView
        didDismissWithButtonIndex:(NSInteger)buttonIndex
{
  NSLog(@"Alert View dismissed with button at index %d",buttonIndex);
}
The buttonIndex tells us which button was pressed to dismiss the view. The index starts at 0 so in our example with two buttons the Cancel button will give a value of 0 and the OK button will give 1. Of course you will probably want to do something more useful than log the result in a real application.

Plain Text Input

With iOS 5 the UIKit framework has added UIAlertView styles that allow for user input directly into the alert view. This is useful when you need to get a small amount of text input from the user such as a username or password before performing a task. The most simple style is to allow plain text input. The code to create and show a plain text input style alert view is as follows:
UIAlertView *alertView = [[UIAlertView alloc]
                           initWithTitle:@"PlainTextStyle"
                           message:@"Enter plain text"
                           delegate:self
                           cancelButtonTitle:@"Cancel"
                           otherButtonTitles:@"OK", nil];

alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
This is similar to creating the default alert view with the exception that we are setting the alertViewStyle property. This property is new in iOS 5 and takes a UIAlertViewStyle to set the style of the alert view. In this case we use UIAlertViewStylePlainTextInput which results in an alert view that looks like this:
The display and dismissal of the keyboard is handled for you to allow the user to enter text into the text field. You can access the text that the user has entered from the delegate we previously used to determine which button was pressed:
UITextField *textField = [alertView textFieldAtIndex:0];
NSLog(@"Plain text input: %@",textField.text);
Note that the text field is accessed via an instance method, textFieldAtIndex, which as the name suggests takes the index of the text field we want. The UIAlertViewStylePlainTextInput alert style contains a single text field at index 0.

Secure Text Input

The plain text input style is obviously not great if the input you want from the user is a password. Typically when entering a password iOS masks characters as they are typed. To get that style of user input we can use the UIAlertViewStyleSecureTextInput:
alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
The resulting UIAlertView looks the same as the plain text version with the exception that characters are masked a few seconds after they are entered:

Login and Password Input

The final style covers the situation where you want to get both a username and a password in a single alert view. The UIAlertViewStyleLoginAndPasswordInput style gives us an alert view that looks as follows:
The login name field is a plain text field and the password field is a secure text field. In this case we have two text fields that we need to retrieve in the delegate method:
UITextField *loginField = [alertView textFieldAtIndex:0];
NSLog(@"Login input: %@",loginField.text);

UITextField *passwordField = [alertView textFieldAtIndex:1];
NSLog(@"Password input: %@",passwordField.text);

Dynamically enabling/disabling the OK button

One minor refinement we can make when expecting input from the user is to only enable the OK button when the user has actually entered some text. To perform this validation we need to implement an extra delegate method:
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
  UITextField *textField = [alertView textFieldAtIndex:0];
  if ([textField.text length] == 0)
  {
    return NO;
  }
  return YES;
}
The alertViewShouldEnableFirstOtherButton delegate method is called each time the user modifies a text input field in the alert view. It return a BOOL which indicates if the first other button (the OK button in our example) should be enabled or not.
Of course you could do some more sophisticated validation if required but in this case we just check if the user has entered some text into the first text input field. If the text field is empty we return NO which disables the OK button. As soon as the user enters at least one character it is enabled. The Cancel button remains enabled at all times.

Wrapping Up

With iOS 5 the UIAlertView class provides a quick and easy way to get a username or password from the user. There is not much code required to implement these additional alert view styles.

DOWNLOAD CODE HERE.

iHope this helped you...

Wednesday 18 July 2012

iOS Fonts

iOS Fonts


Academy Engraved LET
iPhone/iPod                 iPad
AcademyEngravedLetPlain                                5.04.3

American Typewriter
AmericanTypewriter3.04.3
AmericanTypewriter-Bold3.04.3
AmericanTypewriter-Condensed5.05.0
AmericanTypewriter-CondensedBold5.05.0
AmericanTypewriter-CondensedLight5.05.0
AmericanTypewriter-Light5.05.0


Apple Color Emoji
AppleColorEmoji3.04.3

Apple SD Gothic Neo
AppleSDGothicNeo-Bold5.05.0
AppleSDGothicNeo-Medium4.34.3

Arial
ArialMT3.04.3
Arial-BoldItalicMT3.04.3
Arial-BoldMT3.04.3
Arial-ItalicMT3.04.3

Arial Hebrew
ArialHebrew3.04.3
ArialHebrew-Bold3.04.3

Arial Rounded MT Bold
ArialRoundedMTBold3.04.3

Avenir
Avenir-Black6.06.0
Avenir-BlackOblique6.06.0
Avenir-Book6.06.0
Avenir-BookOblique6.06.0
Avenir-Heavy6.06.0
Avenir-HeavyOblique6.06.0
Avenir-Light6.06.0
Avenir-LightOblique6.06.0
Avenir-Medium6.06.0
Avenir-MediumOblique6.06.0
Avenir-Oblique6.06.0
Avenir-Roman6.06.0

Avenir Next
AvenirNext-Bold6.06.0
AvenirNext-BoldItalic6.06.0
AvenirNext-DemiBold6.06.0
AvenirNext-DemiBoldItalic6.06.0
AvenirNext-Heavy6.06.0
AvenirNext-HeavyItalic6.06.0
AvenirNext-Italic6.06.0
AvenirNext-Medium6.06.0
AvenirNext-MediumItalic6.06.0
AvenirNext-Regular6.06.0
AvenirNext-UltraLight6.06.0
AvenirNext-UltraLightItalic6.06.0

Avenir Next Condensed
AvenirNextCondensed-Bold6.06.0
AvenirNextCondensed-BoldItalic6.06.0
AvenirNextCondensed-DemiBold6.06.0
AvenirNextCondensed-DemiBoldItalic6.06.0
AvenirNextCondensed-Heavy6.06.0
AvenirNextCondensed-HeavyItalic6.06.0
AvenirNextCondensed-Italic6.06.0
AvenirNextCondensed-Medium6.06.0
AvenirNextCondensed-MediumItalic6.06.0
AvenirNextCondensed-Regular6.06.0
AvenirNextCondensed-UltraLight6.06.0
AvenirNextCondensed-UltraLightItalic6.06.0

Bangla Sangam MN
BanglaSangamMN3.04.3
BanglaSangamMN-Bold3.04.3

Baskerville
Baskerville3.04.3
Baskerville-Bold3.04.3
Baskerville-BoldItalic3.04.3
Baskerville-Italic3.04.3
Baskerville-SemiBold5.05.0
Baskerville-SemiBoldItalic5.05.0

Bodoni Ornaments
BodoniOrnamentsITCTT5.04.3

Bodoni 72
BodoniSvtyTwoITCTT-Bold5.04.3
BodoniSvtyTwoITCTT-Book5.04.3
BodoniSvtyTwoITCTT-BookIta5.04.3

Bodoni 72 Oldstyle
BodoniSvtyTwoOSITCTT-Bold5.04.3
BodoniSvtyTwoOSITCTT-Book5.04.3
BodoniSvtyTwoOSITCTT-BookIt5.04.3
BodoniSvtyTwoSCITCTT-Book5.04.3

Bradley Hand
BradleyHandITCTT-Bold6.04.3

Chalkboard SE
ChalkboardSE-Bold3.04.3
ChalkboardSE-Light5.05.0
ChalkboardSE-Regular3.04.3

Chalkduster
Chalkduster5.04.3

Cochin
Cochin3.04.3
Cochin-Bold3.04.3
Cochin-BoldItalic3.04.3
Cochin-Italic3.04.3

Copperplate
Copperplate5.04.3
Copperplate-Bold5.04.3
Copperplate-Light5.05.0

Courier
Courier3.04.3
Courier-Bold3.04.3
Courier-BoldOblique3.04.3
Courier-Oblique3.04.3

Courier New
CourierNewPS-BoldItalicMT3.04.3
CourierNewPS-BoldMT3.04.3
CourierNewPS-ItalicMT3.04.3
CourierNewPSMT3.04.3

DB LCD Temp
DBLCDTempBlack6.0
3.0
6.0
4.3

Devanagari Sangam MN
DevanagariSangamMN3.04.3
DevanagariSangamMN-Bold3.04.3

Didot
Didot5.04.3
Didot-Bold5.04.3
Didot-Italic5.04.3

Euphemia UCAS
EuphemiaUCAS6.06.0
EuphemiaUCAS-Bold6.06.0
EuphemiaUCAS-Italic6.06.0

Futura
Futura-CondensedExtraBold3.04.3
Futura-CondensedMedium5.05.0
Futura-Medium3.04.3
Futura-MediumItalic3.04.3

Geeza Pro
GeezaPro3.04.3
GeezaPro-Bold3.04.3

Georgia
Georgia3.04.3
Georgia-Bold3.04.3
Georgia-BoldItalic3.04.3
Georgia-Italic3.04.3

Gill Sans
GillSans5.04.3
GillSans-Bold5.04.3
GillSans-BoldItalic5.04.3
GillSans-Italic5.04.3
GillSans-Light5.05.0
GillSans-LightItalic5.05.0

Gujarati Sangam MN
GujaratiSangamMN3.04.3
GujaratiSangamMN-Bold3.04.3

Gurmukhi MN
GurmukhiMN3.04.3
GurmukhiMN-Bold3.04.3

Heiti SC
STHeitiSC-Light3.04.3
STHeitiSC-Medium3.04.3

Heiti TC
STHeitiTC-Light3.04.3
STHeitiTC-Medium3.04.3

Helvetica
Helvetica3.04.3
Helvetica-Bold3.04.3
Helvetica-BoldOblique3.04.3
Helvetica-Light5.05.0
Helvetica-LightOblique5.05.0
Helvetica-Oblique3.04.3

Helvetica Neue
HelveticaNeue3.04.3
HelveticaNeue-Bold3.04.3
HelveticaNeue-BoldItalic3.04.3
HelveticaNeue-CondensedBlack5.05.0
HelveticaNeue-CondensedBold5.05.0
HelveticaNeue-Italic3.04.3
HelveticaNeue-Light5.05.0
HelveticaNeue-LightItalic5.05.0
HelveticaNeue-Medium5.05.0
HelveticaNeue-UltraLight5.05.0
HelveticaNeue-UltraLightItalic5.05.0

Hiragino Kaku Gothic ProN
HiraKakuProN-W33.04.3
HiraKakuProN-W65.04.3

Hiragino Mincho ProN
HiraMinProN-W33.04.3
HiraMinProN-W63.04.3

Hoefler Text
HoeflerText-Black5.04.3
HoeflerText-BlackItalic5.04.3
HoeflerText-Italic5.04.3
HoeflerText-Regular5.04.3

Kailasa
Kailasa3.04.3
Kailasa-Bold3.04.3

Kannada Sangam MN
KannadaSangamMN3.04.3
KannadaSangamMN-Bold3.04.3

Malayalam Sangam MN
MalayalamSangamMN3.04.3
MalayalamSangamMN-Bold3.04.3

Marion
Marion-Bold5.05.0
Marion-Italic5.05.0
Marion-Regular5.05.0

Marker Felt
MarkerFelt-Thin3.04.3
MarkerFelt-Wide3.04.3

Noteworthy
Noteworthy-Bold5.05.0
Noteworthy-Light5.05.0

Optima
Optima-Bold5.04.3
Optima-BoldItalic5.04.3
Optima-ExtraBlack5.05.0
Optima-Italic5.04.3
Optima-Regular5.04.3

Oriya Sangam MN
OriyaSangamMN3.04.3
OriyaSangamMN-Bold3.04.3

Palatino
Palatino-Bold3.04.3
Palatino-BoldItalic3.04.3
Palatino-Italic3.04.3
Palatino-Roman3.04.3

Papyrus
Papyrus5.04.3
Papyrus-Condensed3.05.0

Party LET
PartyLetPlain5.04.3
Sinhala Sangam MN
SinhalaSangamMN3.04.3
SinhalaSangamMN-Bold3.04.3

Snell Roundhand
SnellRoundhand3.04.3
SnellRoundhand-Black5.05.0
SnellRoundhand-Bold3.04.3

Symbol
Symbol6.06.0

Tamil Sangam MN
TamilSangamMN3.04.3
TamilSangamMN-Bold3.04.3

Telugu Sangam MN
TeluguSangamMN3.04.3
TeluguSangamMN-Bold3.04.3

Thonburi
Thonburi3.04.3
Thonburi-Bold3.04.3

Times New Roman
TimesNewRomanPS-BoldItalicMT3.04.3
TimesNewRomanPS-BoldMT3.04.3
TimesNewRomanPS-ItalicMT3.04.3
TimesNewRomanPSMT3.04.3

Trebuchet MS
Trebuchet-BoldItalic3.04.3
TrebuchetMS3.04.3
TrebuchetMS-Bold3.04.3
TrebuchetMS-Italic3.04.3

Verdana
Verdana3.04.3
Verdana-Bold3.04.3
Verdana-BoldItalic3.04.3
Verdana-Italic3.04.3

Zapf Dingbats
ZapfDingbatsITC5.04.3
Zapfino
Zapfino3.04.3

iHope this helped you...

Thursday 12 July 2012

Simple Examples To Common Tasks


This meant for the relatively new iPhone Developer who just wants simple examples to common tasks.

It is meant as a starting point. Please take the time to read the documentation and understand the SDK in depth.

Logging

In Xcode, click Run > Console to see NSLog statements.
NSLog(@"log: %@ ", myString); NSLog(@"log: %f ", myFloat); NSLog(@"log: %i ", myInt);

Display Images

Display an image anywhere on the screen, without using UI Builder. You can use this for other types of views as well.
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f); UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect]; [myImage setImage:[UIImage imageNamed:@"myImage.png"]]; myImage.opaque = YES; // explicitly opaque for performance [self.view addSubview:myImage]; [myImage release];

Application Frame

Use "bounds" instead of "applicationFrame" -- the latter will introduce a 20 pixel empty status bar (unless you want that..)

Web view

A basic UIWebView.
CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0); UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame]; [webView setBackgroundColor:[UIColor whiteColor]]; NSString *urlAddress = @"http://www.google.com"; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj]; [self addSubview:webView]; [webView release];

Display the Network Activity Status Indicator

This is the rotating icon displayed on the iPhone status bar in the upper left to indicate there is background network activity taking place.
UIApplication* app = [UIApplication sharedApplication]; app.networkActivityIndicatorVisible = YES; // to stop it, set this to NO

Animation: Series of images

Show a series of images in succession
NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"myImage1.png"], [UIImage imageNamed:@"myImage2.png"], [UIImage imageNamed:@"myImage3.png"], [UIImage imageNamed:@"myImage4.gif"], nil]; UIImageView *myAnimatedView = [UIImageView alloc]; [myAnimatedView initWithFrame:[self bounds]]; myAnimatedView.animationImages = myImages; myAnimatedView.animationDuration = 0.25; // seconds myAnimatedView.animationRepeatCount = 0; // 0 = loops forever [myAnimatedView startAnimating]; [self addSubview:myAnimatedView]; [myAnimatedView release];

Animation: Move an object

Show something moving across the screen. Note: this type of animation is "fire and forget" -- you cannot obtain any information about the objects during animation (such as current position). If you need this information, you will want to animate manually using a Timer and adjusting the x&y coordinates as necessary.
CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; theAnimation.duration=1; theAnimation.repeatCount=2; theAnimation.autoreverses=YES; theAnimation.fromValue=[NSNumber numberWithFloat:0]; theAnimation.toValue=[NSNumber numberWithFloat:-60]; [view.layer addAnimation:theAnimation forKey:@"animateLayer"];

NSString and int

The following example displays an integer's value as a text label:
currentScoreLabel.text = [NSString stringWithFormat:@"%d", currentScore];

Draggable items

Here's how to create a simple draggable image.
1. Create a new class that inherits from UIImageView
@interface myDraggableImage : UIImageView { }
2. In the implementation for this new class, add the 2 methods:
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { // Retrieve the touch point CGPoint pt = [[touches anyObject] locationInView:self]; startLocation = pt; [[self superview] bringSubviewToFront:self]; } - (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { // Move relative to the original touch point CGPoint pt = [[touches anyObject] locationInView:self]; CGRect frame = [self frame]; frame.origin.x += pt.x - startLocation.x; frame.origin.y += pt.y - startLocation.y; [self setFrame:frame]; }
3. Now instantiate the new class as you would any other new image and add it to your view
dragger = [[myDraggableImage alloc] initWithFrame:myDragRect]; [dragger setImage:[UIImage imageNamed:@"myImage.png"]]; [dragger setUserInteractionEnabled:YES];

Vibration and Sound

Here is how to make the phone vibrate (Note: Vibration does not work in the Simulator, it only works on the device.)
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Sound will work in the Simulator, however some sound (such as looped) has been reported as not working in Simulator or even altogether depending on the audio format. Note there are specific filetypes that must be used (.wav in this example).
SystemSoundID pmph; id sndpath = [[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"wav" inDirectory:@"/"]; CFURLRef baseURL = (CFURLRef) [[NSURL alloc] initFileURLWithPath:sndpath]; AudioServicesCreateSystemSoundID (baseURL, &pmph); AudioServicesPlaySystemSound(pmph); [baseURL release];

Threading

1. Create the new thread:
[NSThread detachNewThreadSelector:@selector(myMethod) toTarget:self withObject:nil];
2. Create the method that is called by the new thread:
- (void)myMethod { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; *** code that should be run in the new thread goes here *** [pool release]; }
What if you need to do something to the main thread from inside your new thread (for example, show a loading symbol)? UseperformSelectorOnMainThread.
[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:false];

Testing

1. In Simulator, click Hardware > Simulate Memory Warning to test. You may need to enable this setting on each new page of your app.
2. Be sure to test your app in Airplane Mode.

Access properties/methods in other classes

One way to do this is via the AppDelegate:
myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate]; [[[appDelegate rootViewController] flipsideViewController] myMethod];

Random Numbers

Use arc4random(). There is also random(), but you must seed it manually, so arc4random() is preferred.

Timers

This timer will call myMethod every 1 second.
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(myMethod) userInfo:nil repeats:YES];
What if you need to pass an object to myMethod? Use the "userInfo" property.
1. First create the Timer
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(myMethod) userInfo:myObject repeats:YES];
2. Then pass the NSTimer object to your method:
-(void)myMethod:(NSTimer*)timer { // Now I can access all the properties and methods of myObject [[timer userInfo] myObjectMethod]; }
To stop a timer, use "invalidate":
[myTimer invalidate]; myTimer = nil; // ensures we never invalidate an already invalid Timer

Time

Calculate the passage of time by using CFAbsoluteTimeGetCurrent().
CFAbsoluteTime myCurrentTime = CFAbsoluteTimeGetCurrent(); // perform calculations here

Alerts

Show a simple alert with OK button.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"An Alert!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release];

Plist files

Application-specific plist files can be stored in the Resources folder of the app bundle. When the app first launches, it should check if there is an existing plist in the user's Documents folder, and if not it should copy the plist from the app bundle.
// Look in Documents for an existing plist file NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; myPlistPath = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat: @"%@.plist", plistName] ]; [myPlistPath retain]; // If it's not there, copy it from the bundle NSFileManager *fileManger = [NSFileManager defaultManager]; if ( ![fileManger fileExistsAtPath:myPlistPath] ) { NSString *pathToSettingsInBundle = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"]; }
Now read the plist file from Documents
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectoryPath = [paths objectAtIndex:0]; NSString *path = [documentsDirectoryPath stringByAppendingPathComponent:@"myApp.plist"]; NSMutableDictionary *plist = [NSDictionary dictionaryWithContentsOfFile: path];
Now read and set key/values
myKey = (int)[[plist valueForKey:@"myKey"] intValue]; myKey2 = (bool)[[plist valueForKey:@"myKey2"] boolValue]; [plist setValue:myKey forKey:@"myKey"]; [plist writeToFile:path atomically:YES];

Info button

Increase the touchable area on the Info button, so it's easier to press.
CGRect newInfoButtonRect = CGRectMake(infoButton.frame.origin.x-25, infoButton.frame.origin.y-25, infoButton.frame.size.width+50, infoButton.frame.size.height+50); [infoButton setFrame:newInfoButtonRect];

Detecting Subviews

You can loop through subviews of an existing view. This works especially well if you use the "tag" property on your views.
for (UIImageView *anImage in [self.view subviews]) { if (anImage.tag == 1) { // do something } }



            iHOPE THIS DOCUMENT HELPED YOU...