Filipe Mota
Filipe Mota

Reputation: 350

Problems with protobuf compiled files in Objective-C

I'm using Protocol Buffers for Objective-C. I compile the proto files with no problems. But when I add the file.pb.h and file.pb.m to my project they have some setters returning values, which is not permited in Objective-C (at least Xcode gives errors for this). Any one with the same problem or with some sugestion?

@interface FileResultObject_Builder : PBGeneratedMessage_Builder {
@private
  FileResultObject* result;
}

- (FileResultObject*) defaultInstance;

- (FileResultObject_Builder*) clear;
- (FileResultObject_Builder*) clone;

- (FileResultObject*) build;
- (FileResultObject*) buildPartial;

- (FileResultObject_Builder*) mergeFrom:(FileResultObject*) other;
- (FileResultObject_Builder*) mergeFromCodedInputStream:(PBCodedInputStream*) input;
- (FileResultObject_Builder*) mergeFromCodedInputStream:(PBCodedInputStream*) input extensionRegistry:(PBExtensionRegistry*) extensionRegistry;

- (BOOL) hasCheckedIn;
- (BOOL) checkedIn;
- (FileResultObject_Builder*) setCheckedIn:(BOOL) value;
- (FileResultObject_Builder*) clearCheckedIn;

- (BOOL) hasCheckedOut;
- (BOOL) checkedOut;
- (FileResultObject_Builder*) setCheckedOut:(BOOL) value;
- (FileResultObject_Builder*) clearCheckedOut;

- (BOOL) hasDescription;
- (NSString*) description;
- (FileResultObject_Builder*) setDescription:(NSString*) value;
- (FileResultObject_Builder*) clearDescription;

- (BOOL) hasLastModifiedDate;
- (NSString*) lastModifiedDate;
- (FileResultObject_Builder*) setLastModifiedDate:(NSString*) value;
- (FileResultObject_Builder*) clearLastModifiedDate;

- (BOOL) hasCreatedDate;
- (NSString*) createdDate;
- (FileResultObject_Builder*) setCreatedDate:(NSString*) value;
- (FileResultObject_Builder*) clearCreatedDate;

- (BOOL) hasSize;
- (int32_t) size;
- (FileResultObject_Builder*) setSize:(int32_t) value;
- (FileResultObject_Builder*) clearSize;

- (NSArray*) keywordsList;
- (NSString*) keywordsAtIndex:(int32_t) index;
- (FileResultObject_Builder*) replaceKeywordsAtIndex:(int32_t) index with:(NSString*) value;
- (FileResultObject_Builder*) addKeywords:(NSString*) value;
- (FileResultObject_Builder*) addAllKeywords:(NSArray*) values;
- (FileResultObject_Builder*) clearKeywordsList;

- (BOOL) hasDirectory;
- (BOOL) directory;
- (FileResultObject_Builder*) setDirectory:(BOOL) value;
- (FileResultObject_Builder*) clearDirectory;

- (BOOL) hasMimeType;
- (NSString*) mimeType;
- (FileResultObject_Builder*) setMimeType:(NSString*) value;
- (FileResultObject_Builder*) clearMimeType;

- (BOOL) hasResult;
- (ResultObject*) result;
- (FileResultObject_Builder*) setResult:(ResultObject*) value;
- (FileResultObject_Builder*) setResultBuilder:(ResultObject_Builder*) builderForValue;
- (FileResultObject_Builder*) mergeResult:(ResultObject*) value;
- (FileResultObject_Builder*) clearResult;
@end

This is part of the code. The errors are in the setters returning something.

Upvotes: 1

Views: 1079

Answers (1)

phluid
phluid

Reputation: 96

Just came across this very same problem today. Unfortunately the generated Objective-C *_builder classes use an internal property named 'result' to build the actual message. If your protocol buffer message definition also defines a property named 'result' this will, the builder class for that message would generated a setResult: method, which is different from the internal 'result' declaration.

From my perspective, the ideal solution is to patch the Objective-C protocol buffer compiler plugin so that the generated *_Builder classes use a less common name.

You could also change the field name in your message definition. This is not ideal, but at least it wouldn't really break anything as it's the field tag that makes the field unique, not its name. However, depending on your scenario this may not always be possible.

Yet another option is to patch the generated code for the offending class(es). Again, far from ideal, but works as a quick fix, but will continue to break whenever you regenerate the classes.

Here's a quick fix: https://gist.github.com/pdcgomes/7005463

Hope this helps. Cheers.

Upvotes: 1

Related Questions