Pages

Monday, January 23, 2012

What is SQLite?

SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file. The database file format is cross-platform - you can freely copy a database between 32-bit and 64-bit systems or between big-endian and little-endian architectures. These features make SQLite a popular choice as an Application File Format. Think of SQLite not as a replacement for Oracle but as a replacement for fopen()


And it is,
a. Single user
b. File based
c. Cross Platform (can be used across multiple platforms)
d. ANSI based C library i.e., pure C API.

SQLite tools:
- SQLite Manager
- sqlite3 command line utility

Creating the DB through command line:

$ sqlite3 Example.database
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> 

.help for more commands
.quit to quit from the sqlite prompt


After successful creation of database, the sqlite prompt gets opened and we can create tables.

For the SQL queries syntax, please refer http://www.sqlite.org/

Sunday, January 22, 2012

What is UIView's bounds and frame?

The UIView class defines a rectangular area on the screen and the interfaces for managing the content in that area. At runtime, a view object handles the rendering of any content in its area and also handles any interactions with that content. The UIView class itself provides basic behavior for filling its rectangular area with a background color. More sophisticated content can be presented by subclassing UIView and implementing the necessary drawing and event-handling code yourself. The UIKit framework also includes a set of standard subclasses that range from simple buttons to complex tables and can be used as-is. For example, a UILabel object draws a text string and a UIImageView object draws an image.
  
View drawing occurs on an as-needed basis. When a view is first shown, or when all or part of it becomes visible due to layout changes, the system asks the view to draw its contents. For views that contain custom content using UIKit or Core Graphics, the system calls the view’s drawRect: method. Your implementation of this method is responsible for drawing the view’s content into the current graphics context, which is set up by the system automatically prior to calling this method. This creates a static visual representation of your view’s content that can then be displayed on the screen. 

Creating view programmatically:
CGRect  viewRect = CGRectMake(10, 10, 100, 100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];
 
Important method in drawing the content on to the view:
 
drawRect: - Implement this method if your view draws custom content. If your view
does not do any custom drawing, avoid overriding this method. 
 
bounds: - The bounds rectangle, which describes the view’s location and size in its 
own coordinate system.
 
frame: - The frame rectangle, which describes the view’s location and size in its 
superview’s coordinate system.
 
 

iPhone sensors

There are various sensors built into most devices iPhone, iPad, and iPod touch that allow them to perform some of their interface featrures. Without these sensors, none of the devices would be what we know them as today. The sensors are:
Proximity sensor – This sensor can determine how close the iPhone is to your face. This sensor is what helps the iPhone turn off its screen automatically whenever you hold the phone up to your ear. This is necessary to prevent accidental button clicks by the side of your head when talking. This sensor is only on the iPhone (since the other devices don't need it).
Motion sensor/accelerometer – This sensor enables the iPod touch, iPad, or iPhone’s screen to automatically switch from landscape to portrait modes and back again based on whether you’re holding the phone up and down or sideways. This sensor is also present in the iPad.
Ambient Light sensor – This sensor can determine how much light is available in the area surrounding the iPhone, iPod touch, and iPad and automatically adjust the brightness of the screen in order to conserve battery life.
Moisture sensor - The devices also contains a fourth sensor, though this one isn’t related to the interface. The water sensor is a little red tab that appears in the dock connector when the phone has been submerged in water. It can also appear as a red dot in the headphone jack.
iPhone 4 Gyroscope
The iPhone 4, 4th gen. iPod touch, and iPad 2 adds another sensor: a three-axis gyroscope. When combining the gyroscope with the accelerometer, this gives these devices six axes on which the it can operate. This is designed to make them more sensitive, responsive, and powerful for gaming.

Fast Enumeration

This variant of the for loop sets up a fast enumeration. var is a variable whose type can also be declared , expression is an expression that produces a result that conforms to the NSFastEnumeration protocol.Typically, expression is a collection, such as an array or a dictionary.

for ( var in expression )
      programStatement

Ex: for (NSString *empName in employees) {
             NSLog(@"empName = %@", empName);
      }
     
Note: The fast enumeration is not index based like for loop. 


Mac OS X and IOS architecture

Mac OS X Architecture


IOS Architecture

Type Introspection

NSObject is a root class, and so doesn’t have a superclass. It defines the basic framework for Objective-C objects and object interactions. It imparts to the classes and instances of classes that inherit from it the ability to behave as objects and cooperate with the runtime system.

A class that doesn’t need to inherit any special behavior from another class should nevertheless be made a subclass of the NSObject class. Instances of the class must at least have the ability to behave like Objective-C objects at run time. Inheriting this ability from the NSObject class is much simpler and much more reliable than reinventing it in a new class definition.

Type Introspection

Instances can reveal their types at runtime. The isMemberOfClass: method, defined in the NSObject class, checks whether the receiver is an instance of a particular class:

 if ( [anObject isMemberOfClass:someClass] )

    ...


The isKindOfClass: method, also defined in the NSObject class, checks more generally whether the receiver inherits from or is a member of a particular class (whether it has the class in its inheritance path):

if ( [anObject isKindOfClass:someClass] )
    ...
 
The set of classes for which isKindOfClass: returns YES is the same set to which the receiver can be statically typed.
Introspection isn’t limited to type information. Later sections of this chapter discuss methods that return the class object, report whether an object can respond to a message, and reveal other information.
NSObject class reference for more on isKindOfClass:, isMemberOfClass:, and related methods.

Wednesday, January 18, 2012

How to play an audio file on launch of IOS application?


Apple provided a very good framework called ‘AVFoundation’ provides an Objective-C interface for  managing and playing the audio-visual media in your IOS applications.
Please follow the below steps to integrate the audio file to your project:
1. Add the ‘AVFoundation.framework’ to your frameworks folder in the project.
2. Add the statement  #import <AVFoundation/AVFoundation.h>
3. Add the file ‘Output.aif’ (an audio file) to your project.
4. Have the following snippet of code in your viewDidLoad method
NSString *path = [[NSBundle mainBundle] pathForResource:@”Output” ofType:@”aif”];
AVAudioPlayer *theAudio =
        [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
5. Run the application. You will start listening the music.