I like this letter because of the last sentence:
Perhaps Adobe should focus more on creating great HTML5 tools for the future, and less on criticizing Apple for leaving the past behind
Perhaps Adobe should focus more on creating great HTML5 tools for the future, and less on criticizing Apple for leaving the past behind
#import <Cocoa/Cocoa.h>
@interface MyNSController : NSObject {
}
- (IBAction)doSlider:(id)sender;
- (IBAction)doButton:(id)sender;
- (IBAction)doMenu:(id)sender;
@end
#import "MyNSController.h"
@implementation MyNSController
- (IBAction)doSlider:(id)sender
{
float value = [sender floatValue];
NSLog(@"Do Slider. Value = %f", value);
}
- (IBAction)doButton:(id)sender
{
NSLog(@"Do Button");
}
- (IBAction)doMenu:(id)sender
{
NSLog(@"Do Menu");
}
@end
@interface DoButton : NSButtonCell {
}
- (IBAction)DoSomething:(id)sender;
@end
#import <Foundation/Foundation.h>Here is the program output:
@interface First : NSObject
{
int x;
}
- (void)printX;
- (void)setX:(int)value;
@end
@implementation First
+ (void)load
{
NSLog(@"First +load");
}
+ (void)initialize
{
NSLog(@"First. +initialize");
}
- (void)printX
{
NSLog(@"First -printX");
NSLog(@"x=%i", x);
}
- (void)setX:(int)value
{
NSLog(@"First -setX");
x = value;
}
@end
@interface Second : NSObject
{
}
@end
@implementation Second
+ (void)load
{
NSLog(@"Second +load");
}
+ (void)initialize
{
NSLog(@"Second initialize");
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Program starts");
First *first = [First new];
[first printX];
[first setX: 123];
[first printX];
[first release];
[pool drain];
return 0;
}
#import <Foundation/Foundation.h>Mac OS X Reference Library. Key-Value Coding Fundamentals
@interface Person : NSObject
{
NSString* firstName;
NSString* lastName;
}
@end
@implementation Person
- (id)init
{
[super init];
firstName = [[NSString alloc] init];
lastName = [[NSString alloc] init];
return self;
}
- (void)dealloc
{
[firstName release];
[lastName release];
[super dealloc];
}
@end
int main()
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Person* person = [[Person alloc] init];
[person setValue:@"Pavel" forKey:@"firstName"];
[person setValue:@"Gnatyuk" forKey:@"lastName"];
NSLog(@"Name: %@", [person valueForKey:@"firstName"]);
NSLog(@"Last Name: %@", [person valueForKey:@"lastName"]);
[person release];
[pool drain];
return 0;
}
#include <iostream>It is a very simple way. I've never seen NSKeyCodingValue protocol implementation in Cocoa. Of course, it is a really generic and more complicated solution.
using namespace std;
class CPerson
{
char* firstName;
char* lastName;
void setValue(char*& var, const char* value)
{
if (var)
{
free(var);
var = NULL;
}
if (value == NULL)
return;
var = strdup(value);
}
public:
CPerson() : firstName(NULL), lastName(NULL) {}
~CPerson()
{
if (firstName)
free(firstName);
if (lastName)
free(lastName);
}
const char* get(const char* key)
{
if (strcmp(key, "firstName") == 0)
return firstName;
if (strcmp(key, "lastName") == 0)
return lastName;
return NULL;
}
void set(const char* key, const char* value)
{
if (strcmp(key, "firstName") == 0)
return setValue(firstName, value);
if (strcmp(key, "lastName") == 0)
return setValue(lastName, value);
return;
}
};
int main (int argc, char * const argv[])
{
CPerson person;
person.set("firstName", "Pavel");
person.set("lastName", "Gnatyuk");
cout << "Name: " << person.get("firstName") << endl;
cout << "LastName: " << person.get("lastName") << endl;
return 0;
}