Monday, May 22, 2017

Category In Iphone


RedMi Y2 Sale
As an alternative to subclassing, Objective-C categories provide a means to add methods to a class. What’s intriguing, is that any methods that you add through a category become part of the class definition, so to speak. In other words, if you add a method to the NSString class, any instance, or subclass, of NSString will have access to that method.
Defining a category is identical to defining the interface for a class, with one small exception: you add a category name inside a set of parenthesis after the interface declaration. The format is shown below:
@interface ClassToAddMethodsTo (category)
  ...methods go here
@end
For example, below I’ve defined a category that adds a method to the NSString class. The methodreverseString adds the capability to all NSString objects to reverse the characters in the string.
@interface NSString (reverse)
-(NSString *) reverseString;
@end
As with the @interface declaration, the @implementation section changes only in that the category name is added to the definition. Below is the implementation of the interface defined above. Notice how in both cases I added (reverse) , which is the category name I assigned.
@implementation NSString (reverse)
 
-(NSString *) reverseString
{
  NSMutableString *reversedStr;
  int len = [self length];
 
  // Auto released string
  reversedStr = [NSMutableString stringWithCapacity:len];     
 
  // Probably woefully inefficient...
  while (len > 0)
    [reversedStr appendString:
         [NSString stringWithFormat:@"%C", [self characterAtIndex:--len]]];   
 
  return reversedStr;
}
 
@end
What follows is a short example to showing how one might use the above category.
#import 
#import "NSString+Reverse.h"
 
int main (int argc, const char * argv[])
{
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  NSString *str  = [NSString stringWithString:@"Fubar"];
  NSString *rev;
 
  NSLog(@"String: %@", str);
  rev = [str reverseString];
  NSLog(@"Reversed: %@",rev); 
 
  [pool drain];
  return 0;
}
The output of the above example is shown here:
Overriding Methods
Categories can also be used to override methods the class inherits, again, providing an alternative to subclassing. You can always access the overridden method using super . I would assume from an internal (compiler/code generation) perspective, this could lead to less code/overhead as compared to creating a subclass solely to override a method (caveat: I have no proof that is true).
Dividing Source Code into Separate File
Although I haven’t given this a go, categories provide an interesting opportunity to disperse the implementation of a class across one or more files. The Objective-C Programming Guide lists several benefits of this including:
  • Opportunity to group together methods that perform similar tasks.
  • Configuring classes differently for various applications, yet maintaining one set of code.
Naming Conventions
The recommended naming convention for a category is “ClassToAddMethodsTo+CatgoryName” for instance, I used the following filenames for the interface and implementation of the above category code:
  • NSString+Reverse.h
  • NSString+Reverse.m
Caveats
You cannot add instance variables to a class through a category. Also, category names must be unique across an application.

Monday, August 1, 2016

How To Create WiFi Hotspot In Windows 7 Using Command Prompt

 Command : netsh wlan set hostednetwork mode=allow ssid=yourname key=yourpassword

Note: Enter the name of wifi instead of  your name (ssid) and wifi password instead of yourpassword (key) .Please make sure Password must be greater than 8 digits.


You have successfully established the Network Connection.

Sept 3:  Type following command to Start your hosted network (WifiHotspot).
Command : netsh wlan start hosted network

Note: Make sure to turn on the “WiFi” and also enable the Wireless Adapter other wise Command Prompt may says ” your hosted network couldn’t be started ”.


Hey now it's time to Share your Wireless Network Adapter here or some following  steps. 


Share your Wireless Network Adapter 

Step 1:  Open control Panel -> Network and Internet and select Network and Sharing Center.

Step 2:  This window you can see your created network under the original network connection.

Step 3:  Click on  “Change adapter settings” in the left side column of Network and Sharing Center.

Step 4:  Right click on your Wireless Network Adapter and click on properties. Click on “Sharing“ tab. Check the option “Allow other network users to connect through this internet’s connection” option. Mention your newly created hosted network name.

Step 5:  you can check hosted network has shared the network access or not from the Network Sharing and Center

Now you can access computer/Laptop Network from you mobile or other device using wifi.

Saturday, June 8, 2013

How To Add Custom Font Style For UILabel OR UITextViews etc In IPhone

To add custom font  in iphone for UILabel or UITextViews user following steps:

Step1: Add your custom font files into your project using Xcode as a resource


Step2: Add a key UIAppFonts in your Info.plist.

Note: Don't be confused if UIAppFonts converted into Fonts provided by application latest version of Xcode occur automatically .

Step3: Make this key as an array.

For each font you have to enter the full name of your font file (including the extension) as items to the UIAppFonts array like following image:


Step4: Save Info.plist

Step5: Now in your application you can simply call 


[UIFont fontWithName:@"CustomFontName" size:15];

 to get the custom font to use with your UILabels and UITextViews, etc…

Note: your ttf file name might not be the same name that you use when you set the font for your label (you can use the code above to get the "fontWithName" parameter).


To Check Your Custom font Is Included Or Not Use Following Code :
    for (NSString *familyName in [UIFont familyNames]) {
        for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
            NSLog(@"Font Name ->%@", fontName);
        }
    }

Thursday, May 30, 2013

Secret Of Android Mobile Phones

Secret Codes For Android 

1. Complete Information About your Phone
*#*#4636#*#*

This code can be used to get some interesting information about your phone
and battery. It shows following 4 menus on screen:
Phone information
Battery information
Battery history
Usage statistics


2. Factory data reset
*#*#7780#*#*

This code can be used for a factory data reset. It'll remove
following thing
Google account settings stored in your phone
System and application data and settings
Downloaded applications
It'll NOT remove:Current system software and bundled application
SD card files e.g. photos, music files, etc.
Note: Once you give this code, you get a prompt screen asking you to click on
"Reset phone" button. So you get a chance to cancel your operation.


3. Format Android Phone
*2767*3855#

Think before you give this code. This code is used for factory
format. It'll remove all files and settings including the internal memory
storage. It'll also reinstall the phone firmware.
Note: Once you give this code, there is no way to cancel the operation unless
you remove the battery from the phone. So think twice before giving this code.

4. Phone Camera Update
*#*#34971539#*#*

This code is used to get information about phone camera. It shows following 4
menus:
Update camera firmware in image (Don't try this option)
Update camera firmware in SD card
Get camera firmware version
Get firmware update count
WARNING: Never use the first option otherwise your phone camera will stop
working and you'll need to take your phone to service center to reinstall
camera firmware.


5. End Call/Power
*#*#7594#*#*

This one is my favorite one. This code can be used to change the "End Call /
Power" button action in your phone. Be default, if you long press the button, it
shows a screen asking you to select any option from Silent mode, AirPlane
mode and Power off.
You can change this action using this code. You can enable direct power off on
this button so you don't need to waste your time in selecting the option.


6. File Copy for Creating Backup
*#*#273283*255*663282*#*#*

This code opens a File copy screen where you can backup your media files e.g.
Images, Sound, Video and Voice memo.


7. Service Mode
*#*#197328640#*#*

This code can be used to enter into Service mode. You can run various tests
and change settings in the service mode.


8. WLAN, GPS and Bluetooth Test Codes:
*#*#232339#*#* OR *#*#526#*#* OR *#*#528#*#*
- WLAN test (Use
"Menu" button to start various tests)
*#*#232338#*#* - Shows WiFi MAC address
*#*#1472365#*#* - GPS test
*#*#1575#*#* - Another GPS test
*#*#232331#*#* - Bluetooth test
*#*#232337#*# - Shows Bluetooth device address


9. Codes to get Firmware version information:
*#*#4986*2650468#*#* - PDA, Phone, H/W, RFCallDate
*#*#1234#*#* - PDA and Phone
*#*#1111#*#* - FTA SW Version
*#*#2222#*#* - FTA HW Version
*#*#44336#*#* - PDA, Phone, CSC, Build Time, Changelist number


10. Codes to launch various Factory Tests:
*#*#0283#*#* - Packet Loopback
*#*#0*#*#* - LCD test
*#*#0673#*#* OR *#*#0289#*#* - Melody test
*#*#0842#*#* - Device test (Vibration test and BackLight test)
*#*#2663#*#* - Touch screen version
*#*#2664#*#* - Touch screen test
*#*#0588#*#* - Proximity sensor test
*#*#3264#*#* - RAM version
Try These Codes On Your Own Risk

Sunday, January 6, 2013

Some Important Iphone Question Answer

Difference between shallow copy and deep copy?


Ans: Shallow copy is also known as address copy. In this process you only copy address not actual data while in deep copy you copy data.

Suppose there are two objects X and Y. X is pointing to a different array while Y is pointing to different array. Now what I will do is following to do shallow copy.
Char *X = {‘a’,’b’,’c’};
Char *B = {‘r’,’s’,’t’};
Y = A;
Now B is pointing is at same location where A pointer is pointing.Both X and Y in this case sharing same data. if change is made both will get altered value of data.Advantage is that coping process is very fast and is independent of size of array.

while in deep copy data is also copied. This process is slow but Both A and B have their own copies and changes made to any copy, other will copy will not be affected.

What is advantage of categories?

Ans: You can add method to existing class even to that class whose source is not available to you. You can extend functionality of a class without subclassing. You can split implementation in multiple classes.


What is keyword atomic in Objective C?


Ans: When you place keyword atomic with a property, it means at one time only one thread can access it.


What are mutable and immutable types in Objective C?


Ans: Mutable means you can change its contents later but when you mark any object immutable, it means once they are initialized, their values cannot be changed. For example, NSArray, NSString values cannot be changed after initialized.


Swap the two variable values without taking third variable?


Ans:-
int x=10;
int y=5;
x=x+y;
NSLog(@”x==> %d”,x);
y=x-y;
NSLog(@”Y Value==> %d”,y);
x=x-y;
NSLog(@”x Value==> %d”,x);
Thanks to Subrat for answering this question.

Wednesday, June 20, 2012

Property in iphone


Using @property tells the compiler that you intend to access the corresponding member variable through "setter" and "getter" functions, i.e. functions which change the value of the variable or return its value. The warnings you're seeing are because you have not defined the required functions.
your header (.h) file looks something like this:
@property(readwrite, assign)  myPhoto;
Because you've told the compiler that those variables should be accessible through setter and getter functions, you need to define those functions. There are two ways of doing this. The easiest is to use@synthesize, by adding the following to your implementation (.m) file:
@synthesize myPhoto;
The @synthesize line causes the - myPhoto, - setMyPhoto  methods to be generated automatically at compile time. You may also define those methods manually, but doing so is usually unnecessary.
 Let's have look on following the Album class example to use properties.

Here's what it looked like before:
@interface AlbumController : UIViewController
{
    NSString* albumTitle;
    NSString* albumAuther;
}
- (NSString*) albumTitle;
- (NSString*) albumAuther;

- (void) setalbumTitle: (NSString*)input;
- (void) setalbumAuther: (NSString*)input;
@end

Here's what it looks like once converted to properties:
@interface AlbumController : UIViewController
{  
    NSString* albumTitle;
    NSString* albumAuther;
}
@property(retain)NSString* albumTitle;
@property(retain)NSString* albumAuther;
@end

The @property is an Objective-C directive which declares the property. The "retain" in the parenthesis specifies that the setter should retain the input value, and the rest of the line simply specifies the type and the name of the property. 

Insted of "retain" you can also use following some other keyword.
  • assign - does nothing to reference count simply points your variable to the data
  • retain - points your variable to data and adds 1 to reference count, data is guaranteed to be there while your variable is still alive
  • copy - makes a copy of data, points your variable at it and makes the retain count 1

assign - the ivar is set by doing a simple assignment. Implementation:
- (void) setFoo:(NSString *)newFoo {
  foo = newFoo;
}

retain - the ivar is sent the retain message before doing the assignment. Implementation:
- (void) setFoo:(NSString *)newFoo {
  if (foo != newFoo) {
    [foo release];
    foo = [newFoo retain];
  }
}

copy - the ivar is sent the copy message before doing the assignment. Implementation:
- (void) setFoo:(NSString *)newFoo {
  if (foo != newFoo) {
    [foo release];
    foo = [newFoo copy];
  }
}

Thursday, June 7, 2012

How To Remove Background Of UISearchBar in iphone

To remove background of UISearchBar first set search bar background color clear color putting following  one line code
searchBar.backgroundColor = [UIColor clearColor];

After adding Subview of UISearchBar [self.view addSubview:searchBar];
Then use any one Method following code

Method:1
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
                            OR
Method:2
for (UIView *subview in searchBar.subviews) {

        if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {

            [subview removeFromSuperview];

            break;
        }
    }