• Skip to main content
  • Skip to primary sidebar

Ravi Shankar

Tweaking Apps

  • Swift
  • Tech Tips

Develop

How to add Android virtual device in eclipse

August 12, 2013 By Ravi Shankar Leave a Comment

Android Virtual Device are used as simulator to test your Android application instead of using a real device. “No compatible targets were found” is the common message that you will receive while trying to run Android Application Project in eclipse. This occurs if there are no virtual device configured for testing the android apps.

201308121619.jpg

Now let us see how to configure a Android Virtual Device using Android Virtual Device Manager.

Step 1: Launch Android Virtual Device Manager by clicking the AVD icon in eclipse.

201308121631.jpg

Step 2: Click New button in Android Virtual Devices.

201308121632.jpg

Step 3: In the Create new Android Virtual Device (AVD) screen, choose the device simulator that you want and enter the other details as shown below.

201308121634.jpg

The AVD also provides option to configure Front and Back Camera, Memory, Internal and SD card storage. After providing the required details click OK button to confirm and save the changes.

201308121638.jpg

Now you should see the newly added Android Virtual Device in the Device Manager. Running the Android Application would launch your app on the Virtual Device.

201308121654.jpg

Filed Under: Android, Develop Tagged With: Android AVD, Eclipse, Simulator, Virtual Device

Variables in Objective-C

June 26, 2013 By Ravi Shankar Leave a Comment

Objective-C also uses variables for storing data in memory like other programming languages. The variables are defined based on the type data type that will be stored. The general rule followed for naming variable are

  1. Use the camel case convention for variable i.e the first word in lowercase and second word in uppercase. For example if you are planning to store name of station in a variable then you can name it as “stationName”.
  2. You can also find out datatype of variable and name accordingly. For example, “strName” can tell the variable is of string data type and holds a name.
  3. Variables must contain only letters and numbers also it is better to avoid using underscore character.
  4. Be descriptive and avoid single letter or confusing words.

The variables are declared by first defining the datatype, followed by description of variable.

Declaring primitive datatypes

Examples :-

int count = 1;

float width = 23.34;

Declaring Objects

NSString *description;

NSArray *months;

The object variables are preceded with * before the description of variable.

Filed Under: Apple, Develop Tagged With: Apple, Objective C, Variables

Create an example iOS Project using Xcode

June 26, 2013 By Ravi Shankar Leave a Comment

We had already covered the basic overview of Xcode and now we are going see the steps required for creating an sample iOS Project that displays Welcome message on Xcode simulator.

Topics Covered

  1. Create New Project using Xcode.
  2. Add label control to Interface Builder.
  3. Edit label to add Welcome message
  4. Choose simulator in Xcode.
  5. Compile, Build and Run the project in Xcode.

Step 1: Launch Xcode then click FIle -> New -> Project.

201306251050.jpg

Step 2: In the Choose a template for your new project, pick Single View Application under the IOS section and click the Next button.

201306251052.jpg

Note :- We will cover the different templates in detail in future tutorials.

Step 3: Now in Choose options for your new project, enter the name for your project, organisation name and company identifier. In the Devices drop down select iPhone and mark the check box with caption as “Use Storyboards” and “Use Automatic Reference Counting” and click Next button.

201306251100.jpg

Some of the above terms like Storyboards, Automatic Reference Counting will be covered in future tutorials.

Step 4: Specify the location for creating this project and click the Create button.

201306251110.jpg  

Now a new project should be created and you should see a screen as shown below.

201306251115.jpg

Step 5: Select the MainStoryboard.storyboard in the Navigator Pane to access the Interface Builder.

201306251120.jpg

Step 6: Navigate to Utilities section and click Object tab. Scroll down and pick label control from the list then drag and drop the label on to Interface Builder.

201306251123.jpg

201306251123.jpg

Step 7: Edit the label and enter Welcome text.

201306251125.jpg

Step 8: Now select the iPhone simulator under Scheme section in Xcode toolbar.

201306251129.jpg

Step 8: Select Run option on Xcode toolbar or use the keyboard combination of command + R to run the sample project on Xcode simulator for iPhone. command + R will first compile and build the project before launching it on the simulator.

Filed Under: Apple, Develop, iPhone, Xcode Tagged With: Apple, iphone, Xcode

NSLog datatype formatting option in Objective-C

March 4, 2013 By Ravi Shankar Leave a Comment

201303040743.jpg

NSLog in Objective-C is function call that is useful during debugging of a program. A typical NSLog example is

NSLog(@” How to use NSLog”);

The above statement prints the message ” How to use NSLog ” in console window. If you want to print the value of Objective-C variable or data type then you need to pass the relevant formatting parameter depending on data type. We have already seen different datatype and qualifiers in Objective-C, below is example Objective-C program with NSLog formatting option for each datatypes.

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])

{

int i = 5;

float f = 5.3;

double d = 66.76;

long int li = 22;

short int si = 12;

char c = ‘W’;

signed int sint = 34;

unsigned int uint = –23;

int o = 024;

int h = 0xAD;

long long ll = 45;

long double lf = 34.5;

unsigned long long ull = 12;

NSString *msg = @”NSLog Message”;

  

  

@autoreleasepool {

NSLog(@” print int %d”, i);

NSLog(@” print float %f”, f); // use %e for exponential

NSLog(@” print double %f”, d); // use %e for exponential

NSLog(@” print long int %li”, li);

NSLog(@” print short int %i”, si);

NSLog(@” print char %c”, c);

NSLog(@” print signed int %i”, sint);

NSLog(@” print unsigned int %u”, uint);

NSLog(@” print octal %o”, o);

NSLog(@” print hexadecimal %X”, h);

NSLog(@” print long long %lld”, ll);

NSLog(@” print long double %Lf”, lf);

NSLog(@” print unsigned long long %llu”, ull);

NSLog(@” print Object %@”, msg);

  

  

  

}

return 0;

}

The console output of the above Objective-C program is shown below

2013-03-04 07:25:10.187 NSLog Example[362:303] print int 5

2013-03-04 07:25:10.189 NSLog Example[362:303] print float 5.300000

2013-03-04 07:25:10.189 NSLog Example[362:303] print double 66.760000

2013-03-04 07:25:10.190 NSLog Example[362:303] print long int 22

2013-03-04 07:25:10.190 NSLog Example[362:303] print short int 12

2013-03-04 07:25:10.190 NSLog Example[362:303] print char W

2013-03-04 07:25:10.191 NSLog Example[362:303] print signed int 34

2013-03-04 07:25:10.191 NSLog Example[362:303] print unsigned int 4294967273

2013-03-04 07:25:10.192 NSLog Example[362:303] print octal 24

2013-03-04 07:25:10.192 NSLog Example[362:303] print hexadecimal AD

2013-03-04 07:25:10.193 NSLog Example[362:303] print long long 45

2013-03-04 07:25:10.193 NSLog Example[362:303] print long double 34.500000

2013-03-04 07:25:10.194 NSLog Example[362:303] print unsigned long long 12

2013-03-04 07:25:10.194 NSLog Example[362:303] print Object NSLog Message

int %d or %i

float %f or %e

double %f or %e

long int %li

short int %i

char %c

signed int %i

unsigned int %u

octal %o

hexa %X

long long %lld

long double %Lf

unsigned long long %llu

object %@

Filed Under: Apple, Develop, Programming Tagged With: Apple, data type, formatting option, NSLog, Objective C

Different data types in Objective-C

March 3, 2013 By Ravi Shankar Leave a Comment

Objective-C like any other programming languages has different data types like int, float, double, char and id. Data types are used for specifying the kind of data that is being stored in a variable. For example, the below code stores a single character to a variable “flag”

char flag = ‘1’

201303031336.jpg

Data type – char

The Objective-C Char data type can store single character of letter or number or special characters. This is done by enclosing the character with in single quotes.

var example1 = ‘W’ (store letter)   

var example2 = ‘3’ (store number)

var example3 = ‘:’ (store special character)

var example4 = ‘/n’ (backlash character is a special character)

Data type – int

int data type is used for storing positive or negative whole numbers. The range of values that can stored depends on the 32 bit or 64 bit operating system.

int count = 10

int exoctal = 036

int hex = 0xADD2

in the above example 0 preceding the number represents octal value and hex number is preceded with 0x

Date type – float & double

float is used for storing positive or negative decimal numbers.

float exfloat = 2.45

float exfloat2 = -0.345

float exfloat3 = 1.2e4

As shown in the last example, float data type can be represented in scientific notation 1.2e4 which is equivalent 1.2x10th power of 4.

double data type can store twice the range of float.

Data type – BOOL

BOOL is used for storing YES or NO i.e 1 or 0

BOOL flag = 1

Data type – id

id data type is used for storing object of any type.

id myfirstObject

Qualifiers

Qualifiers in Cbjective-C are used for increasing range of the data type and the range is system dependant. Qualifiers are placed just before the data type as shown below. The different qualifiers are long, long long, short, signed and unsigned.

Filed Under: Apple, Develop, iPhone, Programming Tagged With: Apple, data type, iphone, Objective C

XCode’s iOS Simulator for iPhone and iPad

March 2, 2013 By Ravi Shankar Leave a Comment

iOS Simulator in Xcode can be used for testing iOS apps before trying the apps on a live device. Listed below are the different settings and features on iOS Simulator.

Launching iOS Simulator

iOS Simulator can be launched by executing Program on Xcode

Run Program on Xcode : Keyboard Shortcut is Command + R, Menu is Product -> Run

The screenshot of IOS Simulator is shown below.

201303021038.jpg

Another alternate way to launch the iOS Simulator is by using the menu option under

Xcode -> Open Developer Tool -> IOS Simulator

201303021039.jpg

iOS SDK Version

IOS SDK version of iOS Simulator can be determined by clicking the Hardware menu -> Version

201303021112.jpg

Deleting Apps and Settings

Reset Content and Settings option clears all the apps and settings from the simulator. For example if you have changed the app icon, the new icon will not be displayed unless you delete the app from the simulator and re-run the program.

201303021133.jpg

You can also delete individual apps by clicking and holding the installed apps followed by clicking delete mark just like you do on any iOS device.

201303021135.jpg

Choosing the device screen on Simulator

IOS Simulator allows users to choose different device screens such as iPad, iPad (Retina), iPhone, iPhone (Retina 3.5 inch) and iPhone (Retina 4 inch). You can choose the desired screen by navigating to Hardware menu option and selecting the Device.

201303021206.jpg

It is always recommend to try out the apps on the different device simulator before releasing it on the App Store. For example if you are developing an app for the iPhone then you need to try out in all the 4 iPhone device simulator apart from testing your app on live device.

Taking App Screenshots using Simulator

IOS Simulator can be used for taking screenshots of your app for publishing app on the App Store. This is quite useful when you do not have all IOS devices but still want to see the screenshots of your app. The Screenshots can be taken by loading the app on the Simulator and clicking the File menu -> Save Screenshot. The screenshot will be saved to your desktop in .PNG file format.

201303021146.jpg

IOS Simulator also provides option to copy the individual screen from the simulator using the option available as part of the Edit menu.

201303021200.jpg

Other Hardware features

IOS Simulator has features that lets users to see the behaviour of the app on each action such as Rotating Screen to Left, Rotating the Screen to Right, Shake Gesture, Accessing the Home Screen, Locking the Device and also simulating low memory warning.

201303021214.jpg

Simulate Locations

Location menu option under the Debug menu is quite useful for development of location based apps. This lets developers to simulate location required for testing their app.

201303021218.jpg

iOS Simulator Screen Zooming

IOS Simulator screen size can be increased and decreased based on your need using Window -> Scale menu option.

201303021222.jpg

Filed Under: Apple, Develop, ios, iPad, iPhone, Xcode Tagged With: Apple, iOS Simulator, iphone

‘NSInvalidUnarchiveOperationException’, reason: ‘Could not instantiate class named MKMapView’

February 1, 2013 By Ravi Shankar 2 Comments

Problem :- Xcode project with MapView control displays the error “‘NSInvalidUnarchiveOperationException’, reason: ‘Could not instantiate class named MKMapView'”

Solution :- The ‘Could not instantiate class named MKMapView’ error is displayed when the Xcode project with MapView control on xib does not include the MapKit library as part of the Link Libraries.

Select the Xcode project and navigate to Build Phases.

201302010703.jpg

Click the + sign under Link Binary with Libraries and select MapKit,framework from framework and libraries to add selection window.

201302010704.jpg

201302010705.jpg

Now running the project should not display the NSInvalidUnarchiveOperationException.

201302010709.jpg

Filed Under: Develop, Programming Tagged With: MapKit.framework, MKMapView, Objective C

Objective-C – What are Categories?

January 29, 2013 By Ravi Shankar Leave a Comment

Categories in Objective-C are used for adding extra functionality to a class without accessing the source code of the class and without subclassing it. Let us see this with an example by adding an additional method to NSNumber that just writes the value of the NSNumber argument to NSLog.

Create Project

Create a new Command Line Tool project for the example by providing the required details and selecting Type as Foundation.

201301282235.jpg

201301282236.jpg

Add Objective-C Category

Right click on the project, select New File then choose template for your new file as Objective-C category.

201301282251.jpg

Provide the name for your Category and select Category On as NSNumber (The class for which we are adding the additional method)

201301290550.jpg

Write Implementation

Two new files NSNumber+PrintNumber.h and NSNumber+PrintNumber.m files will be added to your project. Define the new method for NSNumber in the header file as shown below.

@interface NSNumber (PrintNumber)

-(void) printNumber: (NSNumber *) num;

@end

where printNumber is the new method that takes num of type NSNumber as the argument.

In the implementation file (NSNumber+PrintNumber.m ), add the code that write the value number to NSLog.

-(void) printNumber: (NSNumber *) num

{

NSLog(@” The number value is %@”, num);

}

Using Categories

Now in main.m file make a call to the new method of NSNumber after importing the “NSNumber+PrintNumber.h” as shown below.

#import <Foundation/Foundation.h>

#import “NSNumber+PrintNumber.h”

int main(int argc, const char * argv[])

{

@autoreleasepool {

  

// insert code here…

NSLog(@”Hello, World!”);

NSNumber *num = [[NSNumber alloc ] initWithInt:25];

[num printNumber:num];

}

return 0;

}

The call to [num printNumber:num] will write the value to the console.

201301290635.jpg

– Categories have access to instance variable of the original class but cannot have its own instance variable.

– Categories on parent class will be available for all its subclass as well.

– Using Categories you can override another method in the class.

–

Filed Under: Develop, Programming Tagged With: iOS, Objective C

  1. Pages:
  2. «
  3. 1
  4. 2
  5. 3
  6. 4
  7. 5
  8. »
« Previous Page
Next Page »

Primary Sidebar

TwitterLinkedin

Recent Posts

  • How to block keywords in Jio broadband
  • How to disable opening an app automatically at login in Mac
  • How to set preferred Wifi network on Mac
  • Attribute Unavailable: Estimated section warning before iOS 11.0
  • How to recover Firefox password from Time Machine backup

Pages

  • About
  • Privacy Policy
  • Terms and Conditions

Copyright 2022 © rshankar.com

Terms and Conditions - Privacy Policy