Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support subclassing RLMObjects #940

Merged
merged 3 commits into from
Sep 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

### Enhancements

* Support subclassing RLMObject models. Although you can now persist subclasses
polymorphic behavior is not supported (i.e. setting a property to an
instance of its subclass).
* Add support for sorting RLMArray properties.
* Speed up inserting objects with `addObject:` by ~20%.
* `readonly` properties are automatically ignored rather than having to be
Expand Down
12 changes: 6 additions & 6 deletions Realm-Xcode6.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
E81A1F9E1955FC9300FDED82 /* RLMObjectStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = E81A1F741955FC9300FDED82 /* RLMObjectStore.mm */; };
E81A1FA01955FC9300FDED82 /* RLMProperty_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = E81A1F751955FC9300FDED82 /* RLMProperty_Private.h */; };
E81A1FA11955FC9300FDED82 /* RLMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = E81A1F761955FC9300FDED82 /* RLMProperty.h */; settings = {ATTRIBUTES = (Public, ); }; };
E81A1FA21955FC9300FDED82 /* RLMProperty.m in Sources */ = {isa = PBXBuildFile; fileRef = E81A1F771955FC9300FDED82 /* RLMProperty.m */; };
E81A1FA21955FC9300FDED82 /* RLMProperty.mm in Sources */ = {isa = PBXBuildFile; fileRef = E81A1F771955FC9300FDED82 /* RLMProperty.mm */; };
E81A1FA41955FC9300FDED82 /* RLMQueryUtil.hpp in Headers */ = {isa = PBXBuildFile; fileRef = E81A1F781955FC9300FDED82 /* RLMQueryUtil.hpp */; };
E81A1FA51955FC9300FDED82 /* RLMQueryUtil.mm in Sources */ = {isa = PBXBuildFile; fileRef = E81A1F791955FC9300FDED82 /* RLMQueryUtil.mm */; };
E81A1FA71955FC9300FDED82 /* RLMRealm_Private.hpp in Headers */ = {isa = PBXBuildFile; fileRef = E81A1F7A1955FC9300FDED82 /* RLMRealm_Private.hpp */; };
Expand Down Expand Up @@ -132,7 +132,7 @@
E856D2031956154C00FB2FCF /* RLMObjectStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = E81A1F741955FC9300FDED82 /* RLMObjectStore.mm */; };
E856D2041956154C00FB2FCF /* RLMProperty_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = E81A1F751955FC9300FDED82 /* RLMProperty_Private.h */; };
E856D2051956154C00FB2FCF /* RLMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = E81A1F761955FC9300FDED82 /* RLMProperty.h */; settings = {ATTRIBUTES = (Public, ); }; };
E856D2061956154C00FB2FCF /* RLMProperty.m in Sources */ = {isa = PBXBuildFile; fileRef = E81A1F771955FC9300FDED82 /* RLMProperty.m */; };
E856D2061956154C00FB2FCF /* RLMProperty.mm in Sources */ = {isa = PBXBuildFile; fileRef = E81A1F771955FC9300FDED82 /* RLMProperty.mm */; };
E856D2071956154C00FB2FCF /* RLMQueryUtil.hpp in Headers */ = {isa = PBXBuildFile; fileRef = E81A1F781955FC9300FDED82 /* RLMQueryUtil.hpp */; };
E856D2081956154C00FB2FCF /* RLMQueryUtil.mm in Sources */ = {isa = PBXBuildFile; fileRef = E81A1F791955FC9300FDED82 /* RLMQueryUtil.mm */; };
E856D2091956154C00FB2FCF /* RLMRealm_Private.hpp in Headers */ = {isa = PBXBuildFile; fileRef = E81A1F7A1955FC9300FDED82 /* RLMRealm_Private.hpp */; };
Expand Down Expand Up @@ -322,7 +322,7 @@
E81A1F741955FC9300FDED82 /* RLMObjectStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RLMObjectStore.mm; sourceTree = "<group>"; };
E81A1F751955FC9300FDED82 /* RLMProperty_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RLMProperty_Private.h; sourceTree = "<group>"; };
E81A1F761955FC9300FDED82 /* RLMProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RLMProperty.h; sourceTree = "<group>"; };
E81A1F771955FC9300FDED82 /* RLMProperty.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RLMProperty.m; sourceTree = "<group>"; };
E81A1F771955FC9300FDED82 /* RLMProperty.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RLMProperty.mm; sourceTree = "<group>"; };
E81A1F781955FC9300FDED82 /* RLMQueryUtil.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RLMQueryUtil.hpp; sourceTree = "<group>"; };
E81A1F791955FC9300FDED82 /* RLMQueryUtil.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RLMQueryUtil.mm; sourceTree = "<group>"; };
E81A1F7A1955FC9300FDED82 /* RLMRealm_Private.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RLMRealm_Private.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -558,7 +558,7 @@
E81A1F731955FC9300FDED82 /* RLMObjectStore.hpp */,
E81A1F741955FC9300FDED82 /* RLMObjectStore.mm */,
E81A1F761955FC9300FDED82 /* RLMProperty.h */,
E81A1F771955FC9300FDED82 /* RLMProperty.m */,
E81A1F771955FC9300FDED82 /* RLMProperty.mm */,
E81A1F751955FC9300FDED82 /* RLMProperty_Private.h */,
E81A1F781955FC9300FDED82 /* RLMQueryUtil.hpp */,
E81A1F791955FC9300FDED82 /* RLMQueryUtil.mm */,
Expand Down Expand Up @@ -1051,7 +1051,7 @@
E856D1FE1956154C00FB2FCF /* RLMObject.mm in Sources */,
E856D2011956154C00FB2FCF /* RLMObjectSchema.mm in Sources */,
E856D2031956154C00FB2FCF /* RLMObjectStore.mm in Sources */,
E856D2061956154C00FB2FCF /* RLMProperty.m in Sources */,
E856D2061956154C00FB2FCF /* RLMProperty.mm in Sources */,
E856D2081956154C00FB2FCF /* RLMQueryUtil.mm in Sources */,
E856D20B1956154C00FB2FCF /* RLMRealm.mm in Sources */,
E856D20E1956154C00FB2FCF /* RLMSchema.mm in Sources */,
Expand Down Expand Up @@ -1120,7 +1120,7 @@
E81A1F9B1955FC9300FDED82 /* RLMObjectSchema.mm in Sources */,
E81A1F9E1955FC9300FDED82 /* RLMObjectStore.mm in Sources */,
3F452EC619C2279800AFC154 /* RLMSwiftSupport.m in Sources */,
E81A1FA21955FC9300FDED82 /* RLMProperty.m in Sources */,
E81A1FA21955FC9300FDED82 /* RLMProperty.mm in Sources */,
E81A1FA51955FC9300FDED82 /* RLMQueryUtil.mm in Sources */,
E81A1FA91955FC9300FDED82 /* RLMRealm.mm in Sources */,
E81A1FAD1955FC9300FDED82 /* RLMSchema.mm in Sources */,
Expand Down
12 changes: 6 additions & 6 deletions Realm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
02E4D6CF192E3DC40082808D /* RLMProperty_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 02E4D69D192E3DC40082808D /* RLMProperty_Private.h */; };
02E4D6D0192E3DC40082808D /* RLMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 02E4D69E192E3DC40082808D /* RLMProperty.h */; settings = {ATTRIBUTES = (Public, ); }; };
02E4D6D1192E3DC40082808D /* RLMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 02E4D69E192E3DC40082808D /* RLMProperty.h */; settings = {ATTRIBUTES = (Public, ); }; };
02E4D6D2192E3DC40082808D /* RLMProperty.m in Sources */ = {isa = PBXBuildFile; fileRef = 02E4D69F192E3DC40082808D /* RLMProperty.m */; };
02E4D6D3192E3DC40082808D /* RLMProperty.m in Sources */ = {isa = PBXBuildFile; fileRef = 02E4D69F192E3DC40082808D /* RLMProperty.m */; };
02E4D6D2192E3DC40082808D /* RLMProperty.mm in Sources */ = {isa = PBXBuildFile; fileRef = 02E4D69F192E3DC40082808D /* RLMProperty.mm */; };
02E4D6D3192E3DC40082808D /* RLMProperty.mm in Sources */ = {isa = PBXBuildFile; fileRef = 02E4D69F192E3DC40082808D /* RLMProperty.mm */; };
02E4D6D4192E3DC40082808D /* RLMQueryUtil.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02E4D6A0192E3DC40082808D /* RLMQueryUtil.hpp */; };
02E4D6D5192E3DC40082808D /* RLMQueryUtil.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02E4D6A0192E3DC40082808D /* RLMQueryUtil.hpp */; };
02E4D6D6192E3DC40082808D /* RLMQueryUtil.mm in Sources */ = {isa = PBXBuildFile; fileRef = 02E4D6A1192E3DC40082808D /* RLMQueryUtil.mm */; };
Expand Down Expand Up @@ -216,7 +216,7 @@
02E4D69C192E3DC40082808D /* RLMObjectStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = RLMObjectStore.mm; sourceTree = "<group>"; };
02E4D69D192E3DC40082808D /* RLMProperty_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RLMProperty_Private.h; sourceTree = "<group>"; };
02E4D69E192E3DC40082808D /* RLMProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RLMProperty.h; sourceTree = "<group>"; };
02E4D69F192E3DC40082808D /* RLMProperty.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RLMProperty.m; sourceTree = "<group>"; };
02E4D69F192E3DC40082808D /* RLMProperty.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RLMProperty.mm; sourceTree = "<group>"; };
02E4D6A0192E3DC40082808D /* RLMQueryUtil.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RLMQueryUtil.hpp; sourceTree = "<group>"; };
02E4D6A1192E3DC40082808D /* RLMQueryUtil.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RLMQueryUtil.mm; sourceTree = "<group>"; };
02E4D6A2192E3DC40082808D /* RLMRealm_Private.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RLMRealm_Private.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -334,7 +334,7 @@
02E4D69B192E3DC40082808D /* RLMObjectStore.hpp */,
02E4D69C192E3DC40082808D /* RLMObjectStore.mm */,
02E4D69E192E3DC40082808D /* RLMProperty.h */,
02E4D69F192E3DC40082808D /* RLMProperty.m */,
02E4D69F192E3DC40082808D /* RLMProperty.mm */,
02E4D69D192E3DC40082808D /* RLMProperty_Private.h */,
02E4D6A0192E3DC40082808D /* RLMQueryUtil.hpp */,
02E4D6A1192E3DC40082808D /* RLMQueryUtil.mm */,
Expand Down Expand Up @@ -747,7 +747,7 @@
02E4D6C2192E3DC40082808D /* RLMObject.mm in Sources */,
02E4D6C8192E3DC40082808D /* RLMObjectSchema.mm in Sources */,
02E4D6CC192E3DC40082808D /* RLMObjectStore.mm in Sources */,
02E4D6D2192E3DC40082808D /* RLMProperty.m in Sources */,
02E4D6D2192E3DC40082808D /* RLMProperty.mm in Sources */,
02E4D6D6192E3DC40082808D /* RLMQueryUtil.mm in Sources */,
02E4D6DC192E3DC40082808D /* RLMRealm.mm in Sources */,
02E4D6E2192E3DC40082808D /* RLMSchema.mm in Sources */,
Expand Down Expand Up @@ -795,7 +795,7 @@
02E4D6C3192E3DC40082808D /* RLMObject.mm in Sources */,
02E4D6C9192E3DC40082808D /* RLMObjectSchema.mm in Sources */,
02E4D6CD192E3DC40082808D /* RLMObjectStore.mm in Sources */,
02E4D6D3192E3DC40082808D /* RLMProperty.m in Sources */,
02E4D6D3192E3DC40082808D /* RLMProperty.mm in Sources */,
02E4D6D7192E3DC40082808D /* RLMQueryUtil.mm in Sources */,
02E4D6DD192E3DC40082808D /* RLMRealm.mm in Sources */,
02E4D6E3192E3DC40082808D /* RLMSchema.mm in Sources */,
Expand Down
11 changes: 8 additions & 3 deletions Realm/RLMAccessor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ static inline void RLMSetValue(__unsafe_unretained RLMObject *obj, NSUInteger co
obj->_row.nullify_link(colIndex);
}
else {
// make sure it is the correct type
if (![[obj.objectSchema.properties[colIndex] objectClassName] isEqualToString:val.objectSchema.className]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks kinda slow, but I guess arrays do the same thing and it's not a major slowdown there. Would be nice to find a nicer solution for checking the type (maybe store the Class in the object schema and just check pointer equality?).

[Ari replied with this, which I accidentally deleted when I just wanted to add my own comment. Sorry!]
Checking the class doesn't work as we have accessor classes. After an object is added to a realm, we could check that the target table index is equal to the table index of the object being inserted. That would avoid objc but would require a few method calls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for either the accessor or standalone class would probably work.

This isn't something important; it's just something that bugs me every time I see it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you it would be nice to improve this. Another thing to consider is for the dynamic interface where we may have vanilla RLMObjects, so I don't think class comparison will work. The only non-string comparison I can think of is comparing table indexes.

Another option is to use uniqued strings for classnames, so that we can compare classname strings using pointer equality. This would require a lot of code change but could be worth it if this is something we have to do all over the place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be really useful to get the dynamic interface working soon. Can I ask the reason why we want vanilla RLMObjects there? I understood that it had something to do with migrations but I can't really see why it would be needed there either.

NSString *reason = [NSString stringWithFormat:@"Can't set object of type '%@' to property of type '%@'",
val.objectSchema.className, [obj.objectSchema.properties[colIndex] objectClassName]];
@throw [NSException exceptionWithName:@"RLMException" reason:reason userInfo:nil];
}

// add to Realm if not in it.
RLMObject *link = val;
if (link.realm != obj.realm) {
Expand Down Expand Up @@ -524,9 +531,7 @@ static Class RLMCreateAccessorClass(Class objectClass,
if (!objectClass || !schema || !accessorClassPrefix) {
@throw [NSException exceptionWithName:@"RLMInternalException" reason:@"Missing arguments" userInfo:nil];
}

// if objectClass is a dicrect RLMSubclass use it, otherwise use proxy class
if (class_getSuperclass(objectClass) != RLMObject.class) {
if (!RLMIsSubclass(objectClass, RLMObject.class)) {
@throw [NSException exceptionWithName:@"RLMException" reason:@"objectClass must derive from RLMObject" userInfo:nil];
}

Expand Down
10 changes: 8 additions & 2 deletions Realm/RLMObjectSchema.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ + (instancetype)schemaForObjectClass:(Class)objectClass createAccessors:(BOOL)cr
schema.className = [objectClass className];
schema.objectClass = objectClass;

// create array of RLMProperties
schema.properties = [self propertiesForClass:objectClass];
// create array of RLMProperties, inserting properties of superclasses first
Class cls = objectClass;
NSArray *props = @[];
while (cls != RLMObject.class) {
props = [[RLMObjectSchema propertiesForClass:cls] arrayByAddingObjectsFromArray:props];
cls = class_getSuperclass(cls);
}
schema.properties = props;

if (NSString *primaryKey = [objectClass primaryKey]) {
for (RLMProperty *prop in schema.properties) {
Expand Down
3 changes: 2 additions & 1 deletion Realm/RLMProperty.m → Realm/RLMProperty.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "RLMObject.h"
#import "RLMSchema_Private.h"
#import "RLMSwiftSupport.h"
#import "RLMUtil.hpp"

@implementation RLMProperty

Expand Down Expand Up @@ -148,7 +149,7 @@ -(BOOL)setTypeFromRawType {

// verify type
Class cls = [RLMSchema classForString:className];
if (class_getSuperclass(cls) != RLMObject.class) {
if (!RLMIsSubclass(cls, RLMObject.class)) {
@throw [NSException exceptionWithName:@"RLMException"
reason:[NSString stringWithFormat:@"'%@' is not supported as an RLMObject property. All properties must be primitives, NSString, NSDate, NSData, RLMArray, or subclasses of RLMObject. See http://realm.io/docs/cocoa/latest/api/Classes/RLMObject.html for more information.", self.objectClassName]
userInfo:nil];
Expand Down
29 changes: 8 additions & 21 deletions Realm/RLMSchema.mm
Original file line number Diff line number Diff line change
Expand Up @@ -77,51 +77,38 @@ - (void)setObjectSchema:(NSArray *)objectSchema {
}
}

static inline bool IsRLMObjectSubclass(Class cls) {
Class parent = class_getSuperclass(cls);
if (parent != RLMObject.class) {
if (parent && RLMIsSubclass(parent, RLMObject.class)) {
@throw [NSException exceptionWithName:@"RLMException"
reason:[NSString stringWithFormat:@"Class '%s' inherits from a RLMObject subclass. This is currently not supported. All model classes must inherit directly from RLMObject and cannot have subclasses of their own.",
class_getName(cls)]
userInfo:nil];
}
return false;
}
return true;
}

+ (void)initialize {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
s_localNameToClass = [NSMutableDictionary dictionary];

NSMutableArray *schemaArray = [NSMutableArray array];
RLMSchema *schema = [[RLMSchema alloc] init];

unsigned int numClasses;
Class *classes = objc_copyClassList(&numClasses);

// first create class to name mapping so we can do array validation
// when creating object schema
s_localNameToClass = [NSMutableDictionary dictionary];
for (unsigned int i = 0; i < numClasses; i++) {
Class cls = classes[i];
if (!IsRLMObjectSubclass(cls)) {
if (!RLMIsSubclass(cls, RLMObject.class)) {
continue;
}

// Delay init of Swift classes until after we know the names of all
// of them so that we can validate array types
NSString *className = NSStringFromClass(cls);
if ([RLMSwiftSupport isSwiftClassName:className]) {
s_localNameToClass[[RLMSwiftSupport demangleClassName:className]] = cls;
}
else {
[schemaArray addObject:[RLMObjectSchema schemaForObjectClass:cls createAccessors:YES]];
s_localNameToClass[className] = cls;
}
}
free(classes);

// process all RLMObject subclasses
for (Class cls in s_localNameToClass.allValues) {
[schemaArray addObject:[RLMObjectSchema schemaForObjectClass:cls createAccessors:YES]];
}
free(classes);

// set class array
schema.objectSchema = schemaArray;
Expand Down
14 changes: 7 additions & 7 deletions Realm/RLMUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ NSArray *RLMValidatedArrayForObjectSchema(NSArray *array, RLMObjectSchema *objec
NSDictionary *RLMValidatedDictionaryForObjectSchema(id value, RLMObjectSchema *objectSchema, RLMSchema *schema);

// C version of isKindOfClass
inline BOOL RLMIsKindOfclass(Class class1, Class class2) {
static inline BOOL RLMIsKindOfclass(Class class1, Class class2) {
while (class1) {
if (class1 == class2) return YES;
class1 = class_getSuperclass(class1);
Expand All @@ -54,21 +54,21 @@ inline BOOL RLMIsKindOfclass(Class class1, Class class2) {
}

// Determines if class1 descends from class2
inline BOOL RLMIsSubclass(Class class1, Class class2) {
static inline BOOL RLMIsSubclass(Class class1, Class class2) {
class1 = class_getSuperclass(class1);
return RLMIsKindOfclass(class1, class2);
}

template<typename T>
inline T *RLMDynamicCast(__unsafe_unretained id obj) {
static inline T *RLMDynamicCast(__unsafe_unretained id obj) {
if ([obj isKindOfClass:[T class]]) {
return obj;
}
return nil;
}

// Translate an rlmtype to a string representation
inline NSString *RLMTypeToString(RLMPropertyType type) {
static inline NSString *RLMTypeToString(RLMPropertyType type) {
switch (type) {
case RLMPropertyTypeString:
return @"string";
Expand All @@ -95,22 +95,22 @@ inline NSString *RLMTypeToString(RLMPropertyType type) {
}

// String conversion utilities
inline NSString * RLMStringDataToNSString(tightdb::StringData stringData) {
static inline NSString * RLMStringDataToNSString(tightdb::StringData stringData) {
static_assert(sizeof(NSUInteger) >= sizeof(size_t),
"Need runtime overflow check for size_t to NSUInteger conversion");
return [[NSString alloc] initWithBytes:stringData.data()
length:stringData.size()
encoding:NSUTF8StringEncoding];
}

inline tightdb::StringData RLMStringDataWithNSString(NSString *string) {
static inline tightdb::StringData RLMStringDataWithNSString(NSString *string) {
static_assert(sizeof(size_t) >= sizeof(NSUInteger),
"Need runtime overflow check for NSUInteger to size_t conversion");
return tightdb::StringData(string.UTF8String,
[string lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
}

// Binary convertion utilities
inline tightdb::BinaryData RLMBinaryDataForNSData(NSData *data) {
static inline tightdb::BinaryData RLMBinaryDataForNSData(NSData *data) {
return tightdb::BinaryData(static_cast<const char *>(data.bytes), data.length);
}
Loading