Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Serializable.h | ||
// ObjectiveMixin | ||
// | ||
// Created by Vladimir Mitrovic on 14/04/2011. | ||
// Copyright 2011 Vladimir Mitrovic. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface Serializable : NSObject {} | ||
- (void) serializeToFile:(NSString*)path; | ||
- (void) deserializeFromFile:(NSString*)path; | ||
@end | ||
|
||
|
||
@protocol SerializableMixin <NSObject> | ||
@required | ||
- (NSString*) serializedRepresentation; | ||
- (void) deserialize:(NSString*)serialized; | ||
|
||
@optional | ||
- (void) serializeToFile:(NSString*)path; | ||
- (void) deserializeFromFile:(NSString*)path; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Serializable.m | ||
// ObjectiveMixin | ||
// | ||
// Created by Vladimir Mitrovic on 14/04/2011. | ||
// Copyright 2011 Vladimir Mitrovic. All rights reserved. | ||
// | ||
|
||
#import "Serializable.h" | ||
|
||
|
||
@implementation Serializable | ||
|
||
- (void) serializeToFile:(NSString*)path { | ||
NSString* serialized = [(id)self serializedRepresentation]; | ||
[serialized writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil]; | ||
} | ||
|
||
- (void) deserializeFromFile:(NSString*)path { | ||
NSString* serialized = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; | ||
[(id)self deserialize:serialized]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// MountainBike.h | ||
// ObjectiveMixin | ||
// | ||
// Created by Vladimir Mitrovic on 14/04/2011. | ||
// Copyright 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "Serializable.h" | ||
|
||
@interface MountainBike : NSObject <SerializableMixin> { | ||
NSString* make; | ||
NSString* model; | ||
} | ||
|
||
@property (nonatomic, retain) NSString* make; | ||
@property (nonatomic, retain) NSString* model; | ||
|
||
- (NSString*) serializedRepresentation; | ||
- (void) deserialize:(NSString*)serialized; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// MountainBike.m | ||
// ObjectiveMixin | ||
// | ||
// Created by Vladimir Mitrovic on 14/04/2011. | ||
// Copyright 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "MountainBike.h" | ||
#import "Mixin.h" | ||
|
||
@implementation MountainBike | ||
@synthesize make; | ||
@synthesize model; | ||
|
||
+ (void) initialize { | ||
[Mixin from:[Serializable class] into:self]; | ||
} | ||
|
||
- (NSString*) serializedRepresentation { | ||
return [NSString stringWithFormat:@"%@,%@", self.make, self.model]; | ||
} | ||
|
||
- (void) deserialize:(NSString*)serialized { | ||
NSArray* components = [serialized componentsSeparatedByString:@","]; | ||
self.make = [components objectAtIndex:0]; | ||
self.model = [components objectAtIndex:1]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters