사용자가 태그 할 수있는 앱용입니다. 태그는 단지 문자열입니다.계산 된 배열 속성의 메모리 의미?
TagHolder
의 배열에는 앱에서 사용중인 모든 태그의 목록이 있으며 태그가 선택되었는지 여부를 알려주는 부울이 있지만 구현 세부 사항입니다.
외부 인터페이스는 selectedTags
및 setSelectedTags:
의 두 가지 메서드를 호출하여 문자열 배열을 반환하고 받아들입니다.
이 두 메서드를 선언 된 속성 selectedTags
에 대한 접근 자로 사용하고 싶습니다.
자, 내 질문은 :
어떤 것이 올바른 메모리 관리의 의미는 그 속성 선언?
@interface TagInfo : NSObject
@property (strong, nonatomic) NSString *tag;
@property (nonatomic) BOOL selected;
@end
@interface SomeClass : NSObject
@property (memorytype, nonatomic) NSArray *selectedTags;
@end
@implementation TagHolder
- (NSArray *)selectedTags
{
// tagInfoArray is an array of all TagInfo objects
NSPredicate *selPred = [NSPredicate predicateWithFormat: @"selected == YES"];
NSArray *selectedTagInfoObjects = [[self tagInfoArray] filteredArrayUsingPredicate: selPred];
NSArray *selectedTags = [selectedTagInfoObjects valueForKey: @"tag"];
return selectedTags;
}
- (void)setSelectedTags: (NSArray *)selectedTags
{
for (TagInfo *tagInfo in [self tagInfoArray]) {
tagInfo.selected = [selectedTags containsObject: tagInfo.tag];
}
}
@end
memorytype
무엇을해야 :
내가 생각하고있는 코드 패턴 (그래서 오타 참아주세요, 코드를 테스트하지)이 무엇입니까? 분명히 강하거나 약한 것은 아니지만, assign
, copy
또는 심지어 unsafe_unretained
중 하나 일 수 있다고 생각하지만 어느 것이 개체 값이있는 계산 된 속성에서 가장 정확한 것일까 요?
저는 일반적으로 ARC를 사용하지만, 수동 유지 횟수가있는 환경에서는 문제가 같아 보입니다.