Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

[ObjC] generating: `- (NSDictionary *) toDict;' for Objective C records #158

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions example/generated-src/objc/TXSItemList.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- (nonnull instancetype)initWithItems:(nonnull NSArray<NSString *> *)items;
+ (nonnull instancetype)itemListWithItems:(nonnull NSArray<NSString *> *)items;

- (nonnull NSDictionary *) toDict;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel like toDict is in line with Cocoa naming conventions

Copy link
Author

Choose a reason for hiding this comment

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

please suggest an alternative name that in your opinion follows the convention.
(in favor of saving time and effort, next time, please make a suggestion next to the original comment :) )


@property (nonatomic, readonly, nonnull) NSArray<NSString *> * items;

@end
9 changes: 8 additions & 1 deletion example/generated-src/objc/TXSItemList.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ + (nonnull instancetype)itemListWithItems:(nonnull NSArray<NSString *> *)items

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p items:%@>", self.class, self, self.items];
return [NSString stringWithFormat:@"<class, %@ : %p, dict, %@>", self.class, self, [[self toDict] description]];
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused about the use of comma and colon here as separators, and find this format hard to understand. I suggest going back to the old format, or maybe using a name=value or name:value layout more consistently across the 3 values you're providing.

}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))
Copy link
Contributor

Choose a reason for hiding this comment

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

This was discussed elsewhere, though I can't see the discussion when scrolling around now. I think this use of a macro is really awkward. I support the alternative of having the generator simply generate the required code for each field, using ?: directly for optional fields, and not for non-optional fields. In this case, the "items" field isn't optional, so there shouldn't be any need to check for null anyway.


return @{@"__class_name__": [self.class description], @"items": _djinni_hide_null_(self.items)};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the use of class_name here a standard thing in ObjC for any other specific format, or something made up for Djinni? It's redundant with the class name output in description currently.

}

@end
29 changes: 24 additions & 5 deletions src/source/ObjcGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {

writeInitializer("-", "init")
if (!r.ext.objc) writeInitializer("+", IdentStyle.camelLower(objcName))
w.wl(s"");
w.wl(s"- (nonnull NSDictionary *) toDict;");

for (f <- r.fields) {
w.wl
Expand Down Expand Up @@ -389,13 +391,28 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
w.wl("- (NSString *)description")
w.braced {
w.w(s"return ").nestedN(2) {
w.w("[NSString stringWithFormat:@\"<%@ %p")
w.w("[NSString stringWithFormat:@\"<%@ %p: dict, %@")
w.w(">\", self.class, self, [[self toDict] description]")
w.wl("];")
}
}
w.wl

for (f <- r.fields) w.w(s" ${idObjc.field(f.ident)}:%@")
w.w(">\", self.class, self")
w.wl("- (NSDictionary *)toDict")
w.braced {
w.wl("#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a macro really necessary? It's a code generator, no reason to avoid repetetive output.
If it absolutely has to be a macro add an#undef when it's no longer needed.

Copy link
Author

Choose a reason for hiding this comment

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

yes, adding a nil value into a NSDictionary will throw an exception and crash.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not questioning the operation itself, but whether it has to implemented with a macro.

Copy link
Author

Choose a reason for hiding this comment

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

i would love to add it to a common file, but unfortunately the generated ObjC code, doesn't define a file that other files include (yet)

Copy link
Author

Choose a reason for hiding this comment

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

@mknejp i see.

i though that doing this with a macro will be more readable, (instead of generating a bunch of repeated code)

also, if i convert the macro into a function, it will be more efficient as self.<name> will be called only once, instead of twice (with the macro)

Copy link
Author

Choose a reason for hiding this comment

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

so can convert to a function or just unroll the code to be repeated, whatever you think is right

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to just unroll it. The generated code only needs to be looked at by people who are developing Djinni, it is not targetted at users. Furthermore, only fields that are marked as optional can ever be nil, so the repetition is not as bad as it seems.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the record, I support unrolling, as well as omitting the code where it's unnecessary (non-optional fields).

w.wl("")
w.w(s"return ").nestedN(2) {
w.w("@{")
w.w("@\"__class_name__\": [self.class description]")

for (f <- r.fields) {
w.w(", ")
w.w(", @\"")
w.w(idObjc.field(f.ident))
w.w("\": ")

w.w("_djinni_hide_null_(")
Copy link
Contributor

Choose a reason for hiding this comment

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

With the new nn nullability support we could check here and only ever call _djinni_hide_null_ when the object is optional.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is nn relevant here? The nn feature is only used for interfaces, and this feature seems to be for records, which aren't (currently) able to contain interfaces. All datatypes in ObjC records will be non-null unless they were declared optional in the .djinni file.

Copy link
Author

Choose a reason for hiding this comment

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

i have replied to the first question above, please take a look.


f.ty.resolved.base match {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this really does need to apply toDict recursively for nested records in order to be a complete feature.
The old code for "description" didn't need that structure in the generator, because it was done at run time. The string formatting using %@ would call description on the subobjects. That's not true for toDict, so I think in it's current form it's only useful as an implementation of description, or for single-level records. I think it should be made general before being merged.

Copy link
Author

Choose a reason for hiding this comment

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

please see the comment / discussion about this above.

case MOptional => w.w(s"self.${idObjc.field(f.ident)}")
case t: MPrimitive => w.w(s"@(self.${idObjc.field(f.ident)})")
Expand All @@ -411,9 +428,11 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
}
case _ => w.w(s"self.${idObjc.field(f.ident)}")
}

w.w(")")
}
}
w.wl("];")
w.wl("};")
}
w.wl

Expand Down
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBAssortedPrimitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
oFthirtytwo:(nullable NSNumber *)oFthirtytwo
oFsixtyfour:(nullable NSNumber *)oFsixtyfour;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly) BOOL b;

@property (nonatomic, readonly) int8_t eight;
Expand Down
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBAssortedPrimitives.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ - (NSUInteger)hash

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p b:%@ eight:%@ sixteen:%@ thirtytwo:%@ sixtyfour:%@ fthirtytwo:%@ fsixtyfour:%@ oB:%@ oEight:%@ oSixteen:%@ oThirtytwo:%@ oSixtyfour:%@ oFthirtytwo:%@ oFsixtyfour:%@>", self.class, self, @(self.b), @(self.eight), @(self.sixteen), @(self.thirtytwo), @(self.sixtyfour), @(self.fthirtytwo), @(self.fsixtyfour), self.oB, self.oEight, self.oSixteen, self.oThirtytwo, self.oSixtyfour, self.oFthirtytwo, self.oFsixtyfour];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"b": _djinni_hide_null_(@(self.b)), @"eight": _djinni_hide_null_(@(self.eight)), @"sixteen": _djinni_hide_null_(@(self.sixteen)), @"thirtytwo": _djinni_hide_null_(@(self.thirtytwo)), @"sixtyfour": _djinni_hide_null_(@(self.sixtyfour)), @"fthirtytwo": _djinni_hide_null_(@(self.fthirtytwo)), @"fsixtyfour": _djinni_hide_null_(@(self.fsixtyfour)), @"oB": _djinni_hide_null_(self.oB), @"oEight": _djinni_hide_null_(self.oEight), @"oSixteen": _djinni_hide_null_(self.oSixteen), @"oThirtytwo": _djinni_hide_null_(self.oThirtytwo), @"oSixtyfour": _djinni_hide_null_(self.oSixtyfour), @"oFthirtytwo": _djinni_hide_null_(self.oFthirtytwo), @"oFsixtyfour": _djinni_hide_null_(self.oFsixtyfour)};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBClientReturnedRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
content:(nonnull NSString *)content
misc:(nullable NSString *)misc;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly) int64_t recordId;

@property (nonatomic, readonly, nonnull) NSString * content;
Expand Down
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBClientReturnedRecord.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ + (nonnull instancetype)clientReturnedRecordWithRecordId:(int64_t)recordId

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p recordId:%@ content:%@ misc:%@>", self.class, self, @(self.recordId), self.content, self.misc];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"recordId": _djinni_hide_null_(@(self.recordId)), @"content": _djinni_hide_null_(self.content), @"misc": _djinni_hide_null_(self.misc)};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
+ (nonnull instancetype)constantsWithSomeInteger:(int32_t)someInteger
someString:(nonnull NSString *)someString;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly) int32_t someInteger;

@property (nonatomic, readonly, nonnull) NSString * someString;
Expand Down
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBConstants.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ + (nonnull instancetype)constantsWithSomeInteger:(int32_t)someInteger

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p someInteger:%@ someString:%@>", self.class, self, @(self.someInteger), self.someString];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"someInteger": _djinni_hide_null_(@(self.someInteger)), @"someString": _djinni_hide_null_(self.someString)};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBDateRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- (nonnull instancetype)initWithCreatedAt:(nonnull NSDate *)createdAt;
+ (nonnull instancetype)dateRecordWithCreatedAt:(nonnull NSDate *)createdAt;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly, nonnull) NSDate * createdAt;

- (NSComparisonResult)compare:(nonnull DBDateRecord *)other;
Expand Down
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBDateRecord.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ - (NSComparisonResult)compare:(DBDateRecord *)other

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p createdAt:%@>", self.class, self, self.createdAt];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"createdAt": _djinni_hide_null_(self.createdAt)};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBEmptyRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
- (nonnull instancetype)init;
+ (nonnull instancetype)emptyRecord;

- (nonnull NSDictionary *) toDict;

@end
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBEmptyRecord.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ + (nonnull instancetype)emptyRecord

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p>", self.class, self];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description]};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBExternRecordWithDerivings.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
+ (nonnull instancetype)externRecordWithDerivingsWithMember:(nonnull DBRecordWithDerivings *)member
e:(DBColor)e;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly, nonnull) DBRecordWithDerivings * member;

@property (nonatomic, readonly) DBColor e;
Expand Down
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBExternRecordWithDerivings.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ - (NSComparisonResult)compare:(DBExternRecordWithDerivings *)other

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p member:%@ e:%@>", self.class, self, self.member, @(self.e)];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"member": _djinni_hide_null_(self.member), @"e": _djinni_hide_null_(@(self.e))};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBMapDateRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- (nonnull instancetype)initWithDatesById:(nonnull NSDictionary<NSString *, NSDate *> *)datesById;
+ (nonnull instancetype)mapDateRecordWithDatesById:(nonnull NSDictionary<NSString *, NSDate *> *)datesById;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly, nonnull) NSDictionary<NSString *, NSDate *> * datesById;

@end
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBMapDateRecord.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ + (nonnull instancetype)mapDateRecordWithDatesById:(nonnull NSDictionary<NSStrin

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p datesById:%@>", self.class, self, self.datesById];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"datesById": _djinni_hide_null_(self.datesById)};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBMapListRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- (nonnull instancetype)initWithMapList:(nonnull NSArray<NSDictionary<NSString *, NSNumber *> *> *)mapList;
+ (nonnull instancetype)mapListRecordWithMapList:(nonnull NSArray<NSDictionary<NSString *, NSNumber *> *> *)mapList;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly, nonnull) NSArray<NSDictionary<NSString *, NSNumber *> *> * mapList;

@end
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBMapListRecord.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ + (nonnull instancetype)mapListRecordWithMapList:(nonnull NSArray<NSDictionary<N

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p mapList:%@>", self.class, self, self.mapList];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"mapList": _djinni_hide_null_(self.mapList)};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBMapRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
+ (nonnull instancetype)mapRecordWithMap:(nonnull NSDictionary<NSString *, NSNumber *> *)map
imap:(nonnull NSDictionary<NSNumber *, NSNumber *> *)imap;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly, nonnull) NSDictionary<NSString *, NSNumber *> * map;

@property (nonatomic, readonly, nonnull) NSDictionary<NSNumber *, NSNumber *> * imap;
Expand Down
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBMapRecord.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ + (nonnull instancetype)mapRecordWithMap:(nonnull NSDictionary<NSString *, NSNum

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p map:%@ imap:%@>", self.class, self, self.map, self.imap];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"map": _djinni_hide_null_(self.map), @"imap": _djinni_hide_null_(self.imap)};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBNestedCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- (nonnull instancetype)initWithSetList:(nonnull NSArray<NSSet<NSString *> *> *)setList;
+ (nonnull instancetype)nestedCollectionWithSetList:(nonnull NSArray<NSSet<NSString *> *> *)setList;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly, nonnull) NSArray<NSSet<NSString *> *> * setList;

@end
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBNestedCollection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ + (nonnull instancetype)nestedCollectionWithSetList:(nonnull NSArray<NSSet<NSStr

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p setList:%@>", self.class, self, self.setList];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"setList": _djinni_hide_null_(self.setList)};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBOptColorRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- (nonnull instancetype)initWithMyColor:(nullable NSNumber *)myColor;
+ (nonnull instancetype)optColorRecordWithMyColor:(nullable NSNumber *)myColor;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly, nullable) NSNumber * myColor;

@end
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBOptColorRecord.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ + (nonnull instancetype)optColorRecordWithMyColor:(nullable NSNumber *)myColor

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p myColor:%@>", self.class, self, self.myColor];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"myColor": _djinni_hide_null_(self.myColor)};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBPrimitiveList.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- (nonnull instancetype)initWithList:(nonnull NSArray<NSNumber *> *)list;
+ (nonnull instancetype)primitiveListWithList:(nonnull NSArray<NSNumber *> *)list;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly, nonnull) NSArray<NSNumber *> * list;

@end
9 changes: 8 additions & 1 deletion test-suite/generated-src/objc/DBPrimitiveList.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ + (nonnull instancetype)primitiveListWithList:(nonnull NSArray<NSNumber *> *)lis

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p list:%@>", self.class, self, self.list];
return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]];
}

- (NSDictionary *)toDict
{
#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))

return @{@"__class_name__": [self.class description], @"list": _djinni_hide_null_(self.list)};
}

@end
2 changes: 2 additions & 0 deletions test-suite/generated-src/objc/DBRecordWithDerivings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
+ (nonnull instancetype)recordWithDerivingsWithKey1:(int32_t)key1
key2:(nonnull NSString *)key2;

- (nonnull NSDictionary *) toDict;

@property (nonatomic, readonly) int32_t key1;

@property (nonatomic, readonly, nonnull) NSString * key2;
Expand Down
Loading