HOW TO BECOME SUCCESFULL CODER IN IOS

subject Type Homework Help
subject Pages 12
subject Words 2023
subject School N/A
subject Course N/A

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
LOKMAN CEYLAN
07010916
IOS FINAL EXAM SOLLUTIONS
GENERAL QUESTIONS
1)Mutable means the values can change,immutable means that once the values have been
set,that it.Quite a few objects in Objective-c have mutable and immutable forms:
NSarray->NSMutableArray
NSString->NSMutableString
NSDictionary->NSMutableDictionary
In conlusion ,if we do not want to change our types ,for example array we use NSarray but
if we want to change or modify our type we use NSMutableArray and mutable types
increas performence and we get best efficency.
2)In order to help you destroy objects when they are no longer needed, Cocoa associates a
counter with each object,which represents what is called the a retain count of the object. In
your program, when you store a reference to an object, you have to let the object know
about that by increasing its retain count by one. When you remove a reference to an object,
you let the object know about that by decreasing its retain count by one. When the retain
count of an object becomes equal to zero, the object knows that it is no longer referenced
anywhere and that it can be destroyed safely. The object then destroys itself, freeing the
associated memory.
For instance, suppose your application is a digital jukebox and you have objects
representing songs and playlists. Suppose that a given song object is referenced by three
playlists objects. If it is not referenced elsewhere, your song object will have a retain count
of three.
Now we Show the retaion on source code :
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableString *myString = [[NSMutableString alloc] initWithString:@"AB"]; //retain
count starts with 1
NSLog(@"RetainCount: %d", [myString retainCount]);
[myString retain]; //here retain count is 2
NSLog(@"RetainCount: %d", [myString retainCount]);
[myString release]; //here retain count is 1
NSLog(@"RetainCount: %d", [myString retainCount]);
[myString release]; //here retain count is 0
[pool drain];
return 0;
}
Output:
Running…
RetainCount: 1
RetainCount: 2
page-pf3
RetainCount: 1
3)
UIButton inherits from UIControl.
UIControl inherits from UIView.
UIView inherits from UIResponder.
UIResponder inherits from the root class NSObject.
4) When we call autorelease on an object programmers had to understand in the days of
manual reference counting was the autorelease pool. When an object was sent the message
autorelease, the autorelease pool would take ownership of an object temporarily so that it
could be returned from the method that created it without burdening the creator or the
receiver with ownership responsibilities. This was crucial for convenience methods that
created a new instance of some object and returned it:
+ (BNRItem *)someItem
{
BNRItem *item = [[[BNRItem alloc] init] autorelease];
return item;
}
Because you had to send the release message to an object to relinquish ownership, the
page-pf4
page-pf5
page-pf6
page-pf7
page-pf8
page-pf9
page-pfa
page-pfb
page-pfc
page-pfd
page-pfe
page-pff
page-pf10
page-pf11
page-pf12

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.