[categories] [index] [all (552)] [latest]
URLNameTransformer.h
#import <Cocoa/Cocoa.h>
@interface URLNameTransformer : NSValueTransformer {
}
+ (Class)transformedValueClass;
+ (BOOL)allowsReverseTransformation;
- (id)transformedValue:(id)value;
@end
URLNameTransformer.m
#import "URLNameTransformer.h"
@implementation URLNameTransformer
+ (Class)transformedValueClass {
return [NSString class];
}
+ (BOOL)allowsReverseTransformation {
return NO;
}
- (id)transformedValue:(id)value {
if (value == nil) {
return value;
} else {
NSURL *url = [NSURL URLWithString:(NSString *)value];
return [url host];
}
}
@end
To use it:
First, register the value transformer
- (void)awakeFromNib {
URLNameTransformer *urlTrans = [[[URLNameTransformer alloc] init] autorelease];
[NSValueTransformer setValueTransformer:urlTrans
forName:@"URLNameTransformer"];
}
Then, set the value transformer in Interface Builder