Created
November 2, 2009 23:50
-
-
Save masakih/224636 to your computer and use it in GitHub Desktop.
コアデータの永続オブジェクトにNSArray(NSString)を使用する
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
コアデータの永続オブジェクトにNSArray(NSString)を使用する。 | |
1、ストアには適当なデリミタで繋げられたNSStringを格納。 | |
2、NSArrayは「一時」「未定義」型の属性として定義。 | |
3、アクセサで分離、結合を行う。 |
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
// | |
// XSPFMInfomationObject.h | |
// XspfManager | |
// | |
// Created by Hori,Masaki on 09/11/02. | |
// Copyright 2009 masakih. All rights reserved. | |
// | |
#import <CoreData/CoreData.h> | |
@class XSPFMXspfObject; | |
@interface XSPFMInfomationObject : NSManagedObject | |
{ | |
} | |
@property (retain) NSArray *voiceActors; | |
@property (retain) NSString * voiceActorsList; | |
@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
// | |
// XSPFMInfomationObject.m | |
// XspfManager | |
// | |
// Created by Hori,Masaki on 09/11/02. | |
// Copyright 2009 masakih. All rights reserved. | |
// | |
#import "XSPFMInfomationObject.h" | |
@implementation XSPFMInfomationObject | |
@synthesize voiceActors; | |
@dynamic voiceActorsList; | |
static NSString *const VoiceActorsDelimiter = @":::"; | |
- (NSArray *)voiceActors | |
{ | |
[self willAccessValueForKey:@"voiceActors"]; | |
NSArray *voiceActors = [self primitiveValueForKey:@"voiceActors"]; | |
[self didAccessValueForKey:@"voiceActors"]; | |
if (voiceActors == nil) { | |
NSString *voiceActorsList = [self valueForKey:@"voiceActorsList"]; | |
if (voiceActorsList) { | |
voiceActors = [voiceActorsList componentsSeparatedByString:VoiceActorsDelimiter]; | |
[self setPrimitiveValue:voiceActors forKey:@"voiceActors"]; | |
} | |
} | |
return voiceActors; | |
} | |
- (void)setVoiceActors:(NSArray *)actors | |
{ | |
[self willChangeValueForKey:@"voiceActors"]; | |
[self setPrimitiveValue:actors forKey:@"voiceActors"]; | |
[self didChangeValueForKey:@"voiceActors"]; | |
[self setValue:[actors componentsJoinedByString:VoiceActorsDelimiter] forKey:@"voiceActorsList"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment