Monday, June 27, 2016

Basic Questionnaire Asked In INTERVIEWS.


NSInteger :

NSInteger is nothing more than a synonym for a long integer. What follows is how NSInteger is defined:

1
2
3
4
5
6
7
#if __LP64__ || NS_BUILD_32_LIKE_64
  typedef long NSInteger;
  typedef unsigned long NSUInteger;
#else
  typedef int NSInteger;
  typedef unsigned int NSUInteger;
#endif

NOTE : NSInteger is a simply an integer

========================================================================

NSNumber :
NSNumber is an Objective-C class, a subclass of NSValue to be specific. You can create an NSNumber object from a signed or unsigned char, short int, int, long int, long long int, float, double or BOOL.
One of the primary distinctions is that you can use NSNumber in collections, such as NSArray, where an object is required. For example, if you need to add a float into an NSArray, you would first need to create an NSNumber object from the float:
1
2
3
4
float percentage = 40.5;
...
// Create NSNumber object, which can now be inserted into an NSArray
NSNumber *percentageObject = [NSNumber numberWithFloat:percentage];

NOTE : NSNumber is an object.

========================================================================

NSValue Object :
This object can not only hold the structures mentioned above, it can also hold scalar types such as integers, floating point numbers, characters, etc. And of course, NSValue objects can be stored within collections.
The code that follows will create CGRect, CGPoint and CGRect structures, corresponding NSValue objects for each, and store the later into an NSArray. The code will also reconstitute the original structures from the NSValue objects.

// CGPoint converted to NSValue
CGPoint point = CGPointMake(9, 9);
NSValue *pointObj = [NSValue valueWithCGPoint:point];  
 
// CGSize converted to NSValue
CGSize size = CGSizeMake(100, 100);
NSValue *sizeObj = [NSValue valueWithCGSize:size];
 
// CGRect from CGPoint and CGSize converted to NSValue
CGRect rect = CGRectMake(point.x, point.y, size.width, size.height);
NSValue *rectObj = [NSValue valueWithCGRect:rect];
 
// Add the objects to a collection
NSArray *array = [NSArray arrayWithObjects:pointObj, sizeObj, rectObj, nil];
 
// Print to console the objects in the collection
NSLog(@"array content: %@", array);
 
// Restore from NSValue to C structures
CGPoint pointRestored = [pointObj CGPointValue];
CGSize sizeRestored = [sizeObj CGSizeValue];
CGRect rectRestored = [rectObj CGRectValue];
 
// Print restored values
NSLog(@"point x:%f y:%f", pointRestored.x, pointRestored.y);
NSLog(@"size  w:%f h:%f", sizeRestored.width, sizeRestored.height);
NSLog(@"rect x:%f y:%f w:%f h:%f", rectRestored.origin.x, rectRestored.origin.y, 
  rectRestored.size.width, rectRestored.size.height);

The output from the NSLog statements is below:

1
2
3
4
5
6
7
8
2013-12-19 13:20:32.808 Sandbox[5324:70b] array content: (
    "NSPoint: {9, 9}",
    "NSSize: {100, 100}",
    "NSRect: {{9, 9}, {100, 100}}"
)
2013-12-19 13:20:32.808 Sandbox[5324:70b] point x:9.000000 y:9.000000
2013-12-19 13:20:32.809 Sandbox[5324:70b] size  w:100.000000 h:100.000000
2013-12-19 13:20:32.810 Sandbox[5324:70b] rect x:9.000000 y:9.000000 w:100.000000 h:100.000000

=======================================================================
Some Definitions :

  1. App ID
    Think of this as an object in Member Center with lots of metadata including:
    • App ID Description
    • App ID Prefix
    • App ID Suffix
    • App Services

  2. App ID Description
    Alphanumeric plus spaces
    Sometimes you are shown this instead of the App ID, or a dropdown is sorted by this App ID
    (I always make this the same as the App ID with the dots changed to spaces)

  3. App ID Prefix
    Select from a list of available hashes in the Team ID format (see below)
    You pretty much always want to select the one labeled "(Team ID)"

  4. App ID Suffix
    A reverse-domain name style string
    This must match the Bundle ID specified in Xcode

  5. Explicit App ID
    Describes an App ID with an App ID Suffix that contains no wildcards
    Can only be associated with a single app (by exactly matching a Bundle ID)
    Compatible with all App Services

  6. Wildcard App ID
    Describes an App ID with an App ID Suffix that ends with an asterisk
    Can be associated with multiple apps (matched similar to CLI/bash shell wildcard matching)
    Not compatible with Game Center, In-App Purchase, or Push Notifications App Services

  7. App Services
    A combination of
    • Data Protection
    • Game Center
    • iCloud
    • In-App Purchase
    • Inter-App Audio
    • Passbook
    • Push Notifications
  8. Team ID
    A 10 character alphanumeric hash
    Unique to every Developer Account (as in the account that costs $99/yr, not every developer on the account)

  9. Apple ID
    A unique integer assigned by Apple when an app is first created in iTunes Connect.

  10. Bundle ID
    A reverse-domain name style string
    Defined in Xcode
    Uniquely identifies an Application Bundle on a device or simulator
    Must have a matching App ID registered with Apple in order to deploy
    Used to distinguish app updates vs. new apps

  11. Application Bundle
    The result of the Build process in Xcode. Though it has an extention of .ipa it is a zip file. The content is a very specific directory structure and holds everything the App needs. It looks like someone took a Mac .app file from /Applications, put in a directory named Payload, zipped it, then change the extension.

  12. Target
    Every Xcode project has at least 1 target. Each target specifies an app that can be built from the project.

  13. SKU
    Apple allows you to store a Stock Keeping Unit string (alphanumeric, cannot have spaces) for each app in iTunes Connect. Apple doesn't do anything with this except display it on reports generated for your record keeping.
========================================================================


Some Strongly Recommended Concepts :


1.strong (iOS4 = retain )
  • it says "keep this in the heap until I don't point to it anymore"
  • in other words " I'am the owner, you cannot dealloc this before aim fine with that same as retain"
  • You use strong only if you need to retain the object.
  • By default all instance variables and local variables are strong pointers.
  • We generally use strong for UIViewControllers (UI item's parents)
  • strong is used with ARC and it basically helps you , by not having to worry about the retain count of an object. ARC automatically releases it for you when you are done with it.Using the keyword strong means that you own the object.
Example:
@property (strong, nonatomic) ViewController *viewController;

@synthesize viewController;

2.weak -
  • it says "keep this as long as someone else points to it strongly"
  • the same thing as assign, no retain or release
  • A "weak" reference is a reference that you do not retain.
  • We generally use weak for IBOutlets (UIViewController's Childs).This works because the child object only needs to exist as long as the parent object does.
  • a weak reference is a reference that does not protect the referenced object from collection by a garbage collector.
  • Weak is essentially assign, a unretained property. Except the when the object is deallocated the weak pointer is automatically set to nil
Example :
@property (weak, nonatomic) IBOutlet UIButton *myButton;

@synthesize myButton;
Strong & Weak Explanation :
Imagine our object is a dog, and that the dog wants to run away (be deallocated).
Strong pointers are like a leash on the dog. As long as you have the leash attached to the dog, the dog will not run away. If five people attach their leash to one dog, (five strong pointers to one object), then the dog will not run away until all five leashes are detached.
Weak pointers, on the other hand, are like little kids pointing at the dog and saying "Look! A dog!" As long as the dog is still on the leash, the little kids can still see the dog, and they'll still point to it. As soon as all the leashes are detached, though, the dog runs away no matter how many little kids are pointing to it.
As soon as the last strong pointer (leash) no longer points to an object, the object will be deallocated, and all weak pointers will be zeroed out.
When we use weak?
The only time you would want to use weak, is if you wanted to avoid retain cycles (e.g. the parent retains the child and the child retains the parent so neither is ever released).


3.retain = strong
  • it is retained, old value is released and it is assigned retain specifies the new value should be sent
  • retain on assignment and the old value sent -release
  • retain is the same as strong.
  • apple says if you write retain it will auto converted/work like strong only.
  • methods like "alloc" include an implicit "retain"
Example:
@property (nonatomic, retain) NSString *name;

@synthesize name;


4.assign
  • assign is the default and simply performs a variable assignment
  • assign is a property attribute that tells the compiler how to synthesize the property's setter implementation
  • I would use assign for C primitive properties and weak for weak references to Objective-C objects.
Example:
@property (nonatomic, assign) NSString *address;

@synthesize address;


5.copy

  • use it for creating a shallow copy of the object
  • good practice to always set immutable properties to copy - because mutable versions can be passed into immutable properties, copy will ensure that you'll always be dealing with an immutable object
  • if an immutable object is passed in, it will retain it - if a mutable object is passed in, it will copy it

6.readonly

  • use it to disable setting of the property (prevents code from compiling if there's an infraction)
  • you can change what's delivered by the getter by either changing the variable directly via its instance variable, or within the getter method itself
====================================================================

Shallow Copy Vs Deep Copy :

Shallow Copy:

The variables A and B refer to different areas of memory, when B is assigned to A the two variables refer to the same area of memory. Later modifications to the contents of either are instantly reflected in the contents of other, as they share contents.
Deep Copy:
  
The variables A and B refer to different areas of memory, when B is assigned to A the values in the memory area which A points to are copied into the the memory area to which B points. Later modifications to the contents of either remain unique to A or B; the contents are not shared.
Share:

0 comments:

Post a Comment