mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 04:20:21 +08:00
39 lines
1.1 KiB
Objective-C
39 lines
1.1 KiB
Objective-C
//
|
|
// NSEntityDescription+RKAdditions.m
|
|
// RestKit
|
|
//
|
|
// Created by Blake Watters on 3/22/12.
|
|
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
|
//
|
|
|
|
#import <objc/runtime.h>
|
|
#import "NSEntityDescription+RKAdditions.h"
|
|
|
|
NSString * const RKEntityDescriptionPrimaryKeyAttributeUserInfoKey = @"primaryKeyAttribute";
|
|
static char primaryKeyAttributeKey;
|
|
|
|
@implementation NSEntityDescription (RKAdditions)
|
|
|
|
- (NSString *)primaryKeyAttribute
|
|
{
|
|
// Check for an associative object reference
|
|
NSString *primaryKeyAttribute = (NSString *) objc_getAssociatedObject(self, &primaryKeyAttributeKey);
|
|
|
|
// Fall back to the userInfo dictionary
|
|
if (! primaryKeyAttribute) {
|
|
primaryKeyAttribute = [self.userInfo valueForKey:RKEntityDescriptionPrimaryKeyAttributeUserInfoKey];
|
|
}
|
|
|
|
return primaryKeyAttribute;
|
|
}
|
|
|
|
- (void)setPrimaryKeyAttribute:(NSString *)primaryKeyAttribute
|
|
{
|
|
objc_setAssociatedObject(self,
|
|
&primaryKeyAttributeKey,
|
|
primaryKeyAttribute,
|
|
OBJC_ASSOCIATION_RETAIN);
|
|
}
|
|
|
|
@end
|