EzDevInfo.com

ios5 interview questions

Top ios5 frequently asked interview questions

iOS 5 Best Practice (Release/retain?)

As a beginning iPhone programmer, what is the best practice for writing apps to be used either with iOS 5 or older versions? Specifically, should I continue using the release/retain of data, or should I ignore that? Does it matter?


Source: (StackOverflow)

To ARC or not to ARC? What are the pros and cons? [closed]

I've yet to use ARC, since the majority of the code in the project I'm working on at the moment was written pre-iOS 5.0.

I was just wondering, does the convenience of not retaining/releasing manually (and presumably more reliable code that comes as a result?) outweigh any 'cost' of using ARC? What are your experiences of ARC, and would you recommend it?

So:

  • How much benefit can ARC bring to a project?
  • Does ARC have a cost like garbage collection in Java?
  • Have you been using ARC and if so, how have you found it so far?

Source: (StackOverflow)

Advertisements

Explanation of strong and weak storage in iOS5

I am new to iOS5 development and using objective-c. I have trouble understanding the difference between strong and weak storage. I have read the documentation and other SO questions, but they all sound identical to me with no further insight.

I read the documentation: Transitioning To ARC - it references to iOS4 terms of retain, assign, and release; which confuses me. Then I look into Open U CS193p, where it differentiates strong and weak:

Strong: "keep this in the heap until I don't point to it anymore"
Weak: "keep this as long as someone else points to it strongly"

Aren't the two definition identical = if pointer no longer pointing to an object, then free the memory holding the object? I understand the concept of pointers, heap, allocation or deallocation of memory - but what's the difference between strong and weak?


Source: (StackOverflow)

iOS5 Storyboard error: Storyboards are unavailable on iOS 4.3 and prior

I've built a small app using storyboards and it ran great. Just before final testing I decided to try it out to see if it runs on iOS 4.3. I clicked on the gray 5.0 in the project settings and selected 4.3.

The app failed to build with the following error message:

Storyboards are unavailable on iOS 4.3 and prior

Both the iPhone and iPad storyboards tell me that.

The issue that when I switched back to iOS5 target, I still keep getting these errors from both storyboards, and the product won't build! I checked: iOS Deployment target in projects settings is 5.0 Target app deployment target is 5.0 Build settings uses iOS 5.0 SDK

What else do I need to do to restore my project to a buildable state? Is this a brand new bug or am I forgetting something?

Update: I kept getting this error even after doing a clean. I changed the debugger in Schemes to "LLDB" and did an additional clean, the project now builds and compiles


Source: (StackOverflow)

Container View Controller Examples [closed]

Can anyone point me to any good examples of creating a Custom View Controller as a Container View Controller? The only documentation I can find is a couple of paragraphs in the UIViewController Class Reference. I feel I need a little more information than that and an example implementation would be nice. Google has turned up nothing at all.

I am specifically interested in the method:

transitionFromViewController:toViewController:duration:options:animations:completion:

Source: (StackOverflow)

How to build for armv6 and armv7 architectures with iOS 5

In iOS5 Apple drops the armv6 architecture from the ARCHS_STANDARD_32_BIT.

In order to keep the support for iPhone3G I still want to compile in armv6 even in iOS5.

Did anyone find a solution for this?


Source: (StackOverflow)

Override setter with arc

@interface Article : NSObject 

@property (nonatomic, strong) NSString *imageURLString;

@end


@implementation Class

@synthesize imageURLString = _imageURLString;

- (void)setImageURLString:(NSString *)imageURLString {
    _imageURLString = imageURLString;
    //do something else
}

Did I correctly override the setter when ARC is enabled?


Source: (StackOverflow)

Is it possible to target older iOS versions when using Xcode 4.2 and iOS 5 SDK?

I just recently downloaded the Xcode 4.2 with iOS 5 SDK package and I immediately noticed that I am unable to use my iPhone 3Gs with iOS 4.2.1 for debugging. I am only able to debug and test on my iphone 4 with iOS 5 installed.

For any of my devices running any iOS less than 5.0 Xcode just says "Finished running for iPhone3GS" and doesn't run it. I have my deployment target set to 3.0 because I am not using any features in my app above 3.0 and I want to be able to target all versions 3.0 or higher. I have all my provisioning profiles installed and up to date.

I have quit and restarted xcode, I have cleaned the build multiple times. I have tried adding armv6 in the archtecture build settings, but nothing will allow me to build and run my app on my old phone with ios 4.2.1.

My question is, is it possible to still make apps with the new SDK work for iOS versions lower than 5? How can I be sure that my app will still run on lower iOS versions if I am unable to install them on my old phone?

Edit: OK it looks like iOS SDK 5 dropped support for armv6 by default. What you have to do is add armv6 in the Architectures field under Build Settings for both your Target and your Project. Then your app will be able to run on iPhone 3G devices. Answer can be found here How to build for armv6 and armv7 architectures with iOS 5


Source: (StackOverflow)

Custom Cell Row Height setting in storyboard is not responding

I am trying to adjust the cell height for one of the cells on my table view. I am adjusting the size from the "row height" setting inside the "size inspector" of the cell in question. When I run the app on my iPhone the cell has the default size set from the "row size" in the table view.

If I change the "row size" of the table view then the size of all cells changes. I do not want to do that as I want a custom size only for one cell. I have seen a lot of posts that have a programmatic solution to the problem, but I would prefer to do it through storyboard, if that is possible.


Source: (StackOverflow)

Some questions about Automatic Reference Counting in iOS5 SDK

I'm currently developing an app for iPad. The development started for iOS 4.2 and is now continuing (and I think will be completed) for iOS 4.3. I just read about ARC in iOS 5, and basically I understood that we will never need to release and retain objects anymore. My questions are:

  1. If I decide to upgrade to iOS 5, do I need to remove all [myObject retain] and [myObject release] statements from my code?

  2. If I develop a new app for iOS 5 using ARC, will I need to implement some sort of "retro-compatibility" checks? i.e.: will I need to check the version of iOS and call retain and release accordingly? So, basically, is ARC available for all iOS versions or just for iOS 5?


Source: (StackOverflow)

Enabling auto layout in iOS 6 while remaining backwards compatible with iOS 5

What is the best way to take advantage of the new auto layout features of iOS 6 while still providing compability with older devices on earlier versions of iOS?


Source: (StackOverflow)

UIView Infinite 360 degree rotation animation?

I'm trying to rotate a UIImageView 360 degrees, and have looked at several tutorials online. I could get none of them working, without the UIView either stopping, or jumping to a new position.

  • How can I achieve this?

The latest thing I've tried is:

[UIView animateWithDuration:1.0
                      delay:0.0
                    options:0
                 animations:^{
                     imageToMove.transform = CGAffineTransformMakeRotation(M_PI);
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];

But if I use 2*pi, it doesn't move at all (since it's the same position). If I try to do just pi (180 degrees), it works, but if I call the method again, it rotates backwards.

EDIT:

[UIView animateWithDuration:1.0
                      delay:0.0
                    options:0
                 animations:^{
                     [UIView setAnimationRepeatCount:HUGE_VALF];
                     [UIView setAnimationBeginsFromCurrentState:YES];
                     imageToMove.transform = CGAffineTransformMakeRotation(M_PI);
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];

doesn't work either. It goes to 180 degrees, pauses for a split second, then resets back to 0 degrees before it starts again.


Source: (StackOverflow)

Xcode 4.2 - declaration of '...' will not be visible outside of this function warning

I use Apple Reachability class from Apple Sample code Reachability

in Xcode 4.2 and new Apple 3.0 compiler I get warning in this class that

+ (Reachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress;

*declaration of 'struct sockaddr_in*' will not be visible outside of this function*

I am not good at classic C %) so I dont understand how I can fix this warning or may be I can ignore it at all.

Thx


Source: (StackOverflow)

Disable Automatic Reference Counting for Some Files

I have downloaded the iOS 5 SDK and found that ARC is a great feature of the new Apple compiler. For the time being, many third party frameworks don't support ARC. Could I use ARC for my new code and keep the current retain/release code unchanged? The ARC converter doesn't work here, because some frameworks, such as JSONKit, cannot be converted to ARC by using the converter.

Edit:

The answer is to add -fno-objc-arc to the compiler flags for the files you don't want ARC. In Xcode 4, you can do this under your target -> Build Phases -> Compile Sources.


Source: (StackOverflow)

Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects

I'm currently using the iOS 5 SDK trying to develop my app. I'm trying to make an NSString a property, and then to synthesize it in the .m file (I have done this before with no issues). Now, I came across this: "Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects."

This is my code: .h

@interface ViewController : UIViewController {
     NSString *newTitle;
}
@property (strong, nonatomic) NSString *newTitle;

.m

@synthesize newTitle;

Does anyone have a clue how I could fix this? Thanks!!


Source: (StackOverflow)