Tuesday, August 23, 2011

Useful Cygwin Commands

find -name \*.jpg
Finds all the files with extension as "jpg" including the subfolders.


ls - list (equivalent to dir in Windos)
cd - change directory


Monday, August 15, 2011

Objective C : NSConstantString(instance) does not recognize

In my attempt to understand Objective C, I have been doing a lot of testing and code writing.
Among many error I encountered, I would like to mention this one in particular since I was unable find much information about this in the internet.

ds@mypc ~/bsp/Cocoa/obj
$ TestAppPhotographer.exe
: Uncaught exception NSInvalidArgumentException, reason: NSConstantString(instance) does not recognize setCaption:

The reson I was getting this error message was due to the fact that when I created an init method to set initial values for our instance variables, I missed a like to "return self;".

Before:

-(id) init
{
if( self = [super init])
{
[self setCaption:@"Default Caption"];
[self setPhotographer:@"Default Photographer"];
}
}

After :

- (id) init
{ if ( self = [super init] )
{ [self setCaption:@"Default Caption"];
[self setPhotographer:@"Default Photographer"];
}
return self;
}

Once I added the above piece of code, it ran okay.

Photographer.h


#import

@interface Photographer : NSObject
{
NSString* caption;
NSString* photographer;
}

-(NSString*) caption;
-(NSString*) photographer;


-(void) setCaption: (NSString*)input;
-(void) setPhotographer: (NSString*) input;
@end


Photographer.m


#import
#import "Photographer.h"


@implementation Photographer

-(NSString*) caption
{
return caption;
}

-(NSString*) photographer
{
return photographer;
}

-(void) setCaption: (NSString*) input
{
//not using garbage collection, we need to release the old object, and retain the new one.
[caption autorelease];
caption = [input retain];
}

-(void) setPhotographer: (NSString*) input
{
[photographer autorelease];
photographer = [input retain];
}


- (id) init
{ if ( self = [super init] )
{ [self setCaption:@"Default Caption"];
[self setPhotographer:@"Default Photographer"];
}
return self;
}

@end


Main.m

#import
#import "Photographer.h"


int main (int argc, char *argv[])
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

Photographer *me = [[Photographer alloc] init];

[me setCaption: @"hello"];
NSLog(@"The caption is %@", [me caption]);

[pool drain];
return 0;
}

GNUmakefile

# Set a path variable to gnustep library directory
export GNUSTEP_MAKEFILES=/c/GNUstep/gnustep/System/Library/Makefiles

# Common Makefile Variables
include $(GNUSTEP_MAKEFILES)/common.make

# Console Project
include $(GNUSTEP_MAKEFILES)/tool.make

# Output Name
TOOL_NAME = TestAppPhotographer

# Source Files
TestAppPhotographer_OBJC_FILES = Main.m Photographer.m

# Class Header (Interface) files
TestAppPhotographer_HEADER_FILES = Photographer.h

# Additional Rules
-include GNUmakefile.preamble

# Objective C Rules
include $(GNUSTEP_MAKEFILES)/tool.make

# Additional Rules
-include GNUmakefile.postamble

Friday, August 12, 2011

Objective C : Difference between instance method (-) and the class method (+)

Ever since I started reading out the Objective C development. This term has come up many times.

Since, being from a .Net background I am always trying to compare the Objective C to .Net ( which is not what I should be doing but it helps me to grasp the idea quickly).

Hence, after running some research I was able to understand the difference between the class method and instance method in Objective C.

Well, “class method” is what we call static method in C#, while instance methods are only available once we have instantiated the object.

E.g

@interface DeepsClass : NSObject

+ (void)myClassMethod;
- (void)myInstanceMethod;

@end

It can now be used like this : -

[DeepsClass myClassMethod];

DeepsClass *object = [[DeepsClass alloc] init];
[object myInstanceMethod];

Thursday, August 4, 2011

IB : FAQ

Nothing on the Transaction Listing dropdown even thou the account is populated:

if (acc.Permissions.Contains(PermissionEnum.ShowTransactions))
{
ddlAccounts.Items.Add(new ListItem(acc.AccountNumber + " " + acc.AccountName + "- Available: " + String.Format("{0:C}", acc.AvaliableBalance / 100), acc.AccountNumber));
}