iPhone Development

Just another iPhone Blog

Tag Archives: iPhone

Core Data v/s SQL Database

Found a Nice Article here

Advertisements

Search 4 Twitter xAuth and OAuth Samples ENDS here

Hello,

This post is place where you will be re-directed to places where you learn about xAuth and OAuth w.r.t Twitter, Take away Sample code of Twitter Engine supporting xAuth and OAuth both for i[Phone] OS and Mac OS Platforms

  1. Official Twitter API Documentation
  2. xAuth Explained
  3. xAuth for Browserless Token Exchange
  4. OS X 10.5 Demo With Sample Code [See References section in that site]
  5. iPhone xAuth Explained with Sample Code
  6. MGTwitterEngine xAuth Support
  7. Testing TwitPIC OAUTH

 

 

Others

  • iPhone Dev SDK – Twitter Agent
  • SlideShow Presentation
  •  

    Hope this Helps!!

    Have Fun 🙂

    Efficient Memory Handling in UIViewController-Part 2

    In the last post we discussed about the skeleton of a typical UIViewController which handles memory warning efficiently.

    In this post, I will provide you Xcode Templates of a UIViewController, which takes care of all these things we have discussed earlier here, thus making our Lives easier.

    Following steps explain How to add these templates:

  • Navigate to Developer->Platforms->iPhoneOS.platform->Developer->Library->Xcode->File Templates->Cocoa Touch Class Folder
  • KEEP A BACKUP OF "UIViewController subclass" folder
  • Download the zip filehere
  • Unzip the file and replace the “UIViewController subclass” folder with the new one
  •  

    Please note that these templates works for UIViewControllers created with File->New File option

    Thats it, there should be no more hassles with Memory now!!

    Happy Coding!! 🙂

    UISegmentControl + Toggle

    Here is one way to give Toggle property to UISegmentedControl

    @interface ToggleSegmentControl : UISegmentedControl

    {

    NSUInteger selectedSegment;//To Keep a Backup of Selected Segment

    }

     

    @end

     

     

    @implementation ToggleSegmentControl

     

    – (id)initWithFrame:(CGRect)frame {

    if (self = [super initWithFrame:frame])

    {

    // Initialization code selectedSegment = self.selectedSegmentIndex;

    }

    return self;

    }

     

    -(void)awakeFromNib {

    selectedSegment = self.selectedSegmentIndex;

    }

     

    – (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

     

    {

    //Check if both segments are equal

    //self.selectedSegmentIndex will have the updated value, where as selectedSegment will contain the old value

    if( selectedSegment == self.selectedSegmentIndex && selectedSegment!=-1)

    {

    //if both are some, deselect the selected segment self.selectedSegmentIndex=-1; selectedSegment=-1; } else { selectedSegment=self.selectedSegmentIndex;

    }

    }

     

    @end


    Autocapitalizing string

    This code snippet requires RegexLite Library.Check here

    #import “RegexKitLite.h”

    @interface NSString(RegExAdditons)

     

    +(NSString*)autocapitalizedStringForString:(NSString*)inString;

     

    @end

     

     

    @implementation NSString(RegExAdditons)

     

    +(NSString*)autocapitalizedStringForString:(NSString*)inString

    {

    NSMutableString *completedString =[NSMutableString stringWithString:@””];

    if( inString && ![inString isEqualToString:@””])

    {

     

    /* Regular Expression for extracting the words in a sentence*/

    NSString   *regexString  = @”(\\w*)”;

    completedString =[NSMutableString stringWithString:inString];

     

    NSUInteger totalLength = [completedString length];

    NSUInteger currentIndex=0;

     

    /* With the help of RegexLite, we extract all the words in the given string*/

    NSArray * components = [inString componentsMatchedByRegex:regexString];

    int index =0, count = [components count];

     

    for( ; index < count;index++) {

     

    NSString *matchedString = [components objectAtIndex:index];

     

    NSUInteger matchedStringLength = [matchedString length];

    if( matchedStringLength>0) {

    unichar character=;

    [matchedString getCharacters:&character range:NSMakeRange(0, 1)];

     

    /* if the first character of the word is a ASCII character, then change the letter to its Upper Case version*/

    if( isascii(character) ) {

     

    /*Find the Location of the First letter of the matchedString within the given string*/

    NSRange range = [completedString rangeOfString:matchedString options:NSLiteralSearch range:NSMakeRange(currentIndex, totalLength-currentIndex)];

     

    if( range.location != NSNotFound) {

     

    /*replace the first letter of the matched string to its upper case version*/

    [completedString replaceCharactersInRange:NSMakeRange(range.location, 1) withString:[NSString stringWithFormat:@”%c”, toupper(character)]];


    currentIndex+=matchedStringLength;

    }

    }

    }

    }

    }

    return completedString;

    }

    @end


     

    @protocol – nothing but a set of rules

    Abstract classes in C++, Interfaces in Java, @protocols in Objective C.. They all serve the same purpose

    What are protocols??

    As described in the title, they define Set of Rules

    When do we use them??

    “When two strangers (In our OOPs world, they refer to two objects whose identity is not known to each other) need to establish a communication, we use protocols to bridge the communication gap between them”

    Let us see the usage of protocols with a real world example

    Let us say two members from a different smuggling gang say GangA and GangB needs to exchange the commodities between them. Then in order to prove their identities they follow certain rules, in other words Protocols,described below

    Gang A to Gang B : tell me the secret code Gang A to Gang B : secret code accepted Gang B to Gang A : share your secret code Gang B to Gang A : your secret code is accepted

    If the conversation happens to be in order above, then we can say the Gang A and Gang B members are valid persons

    So, Let us transform this whole example into our Programming world using Objective C language by Defining two classes for Gang A and Gang B

    GangA.h

    @interface GangA:NSObject<GangAProtocol>

    {

    NSObject<GangBProtocol> * gangBMember;

    }

    @property(nonatomic,assign)NSObject<GangBProcotol>* gangBMember

    @end

    /* Defines what conversation is expected in order to speak with GangB member.. So The Gang B members should implement these methods to prove  */

    @protocol GangBProtocol

    -(NSString*)tellMeTheSecretCode;//Request the GangB member for secret code

    -(void)secretCodeAccepted:(BOOL)isAccepted;//Inform whether they are Authenticated or not

    @end

     

    GangB.h

    @interface GangB:NSObject<GangBProtocol> {

    NSObject<GangAProtocol> gangAMember;

    } @property(nonatomic,assign)NSObject<GangAProtocol> gangAMember; @end

    /* Defines what conversation is expected in order to speak with GangA member.. So The Gang A members should implement these methods to prove their identity  */

    @protocol GangBProtocol

    -(NSString*)shareYourSecretCode;//Request the GangB member for secret code

    -(void)yourCodeIsAccepted:(BOOL)isAccepted;//Inform whether they are Authenticated or not

    @end

    Most of the code is self-explatory. To summarize

    * GangA class would have access to a GangB member which implements GangBProtocol which helps GangA member to establish communication and check their identity and the same holds for GangB class

    * Each class would declare a Protocol on how the other gang members would be expected to respond to their queries and implement the methods in the protocol defined by other gang class i.e. GangA class declares GangB protocol on how it expects to communicate with GangB while implementing the GangA protocol defined in GangB class

    [Although the protocols in the two classes in the example means the same, i have just added them to illustrate the situation where two objects of unknown identity communicates by aggreeing on to some common terms] To Summarize, Protocols are used

    * When we want to establish communication between two object whose identity or Class type is not required to be known to each other

    * When we want to establish communication between two objects, where one object knows the class type to which it is communicating while other Objects need not know the identity of the object at the other end. Eg: Delegate mechanism

    %d bloggers like this: