protobuf/objectivec
2018-08-22 11:55:30 -07:00
..
DevTools Update code to work for Xcode 10b1 () 2018-06-05 15:14:19 -04:00
google/protobuf Update generated descriptors. 2018-08-08 17:21:04 -07:00
ProtocolBuffers_iOS.xcodeproj Remove the iOS Test App. 2018-04-20 17:26:38 -04:00
ProtocolBuffers_OSX.xcodeproj Update Xcode settings 2018-04-06 10:37:14 -04:00
Tests Replace repo links. 2018-08-22 11:55:30 -07:00
.gitignore Expand the OS X/Xcode gitignores 2016-05-19 10:08:51 -04:00
generate_well_known_types.sh Fix cp -r usage to be portable. 2016-04-29 11:31:57 -07:00
GPBArray_PackagePrivate.h Alpha 1 drop of Google's Objective C plugin and runtime support for protobufs. 2015-05-06 13:19:14 -04:00
GPBArray.h Removes trailing whitespaces 2017-02-07 11:57:53 -05:00
GPBArray.m Update code to work for Xcode 10b1 () 2018-06-05 15:14:19 -04:00
GPBBootstrap.h Fixes and expands comments on how to use GPB_ENUM_FWD_DECLARE 2016-12-14 11:35:44 -05:00
GPBCodedInputStream_PackagePrivate.h Migrate away from deprecated OSAtomic APIs. () 2018-01-22 16:26:39 -05:00
GPBCodedInputStream.h Adds pushLimit: and popLimit: into GPBCodedInputStream () 2016-10-27 16:06:45 -04:00
GPBCodedInputStream.m Replace repo links. 2018-08-22 11:55:30 -07:00
GPBCodedOutputStream_PackagePrivate.h HeaderDoc support in the library and generated sources 2016-03-07 12:07:03 -05:00
GPBCodedOutputStream.h ObjC: Document the exceptions on some of the writing apis. 2017-06-19 10:33:45 -04:00
GPBCodedOutputStream.m Check return value on write of raw pointer 2018-03-08 16:20:37 +01:00
GPBDescriptor_PackagePrivate.h ObjC: Preserve unknown fields in proto3 syntax files. 2017-06-06 10:44:14 -04:00
GPBDescriptor.h [ObjC] Add ability to introspect list of enum values () 2018-05-29 08:08:00 -04:00
GPBDescriptor.m Update code to work for Xcode 10b1 () 2018-06-05 15:14:19 -04:00
GPBDictionary_PackagePrivate.h Beta quality drop of Objective C Support. 2015-06-08 17:17:22 -04:00
GPBDictionary.h Reduce size of GPBDictionary by getting rid of class creation methods 2017-11-14 15:37:28 -08:00
GPBDictionary.m Update code to work for Xcode 10b1 () 2018-06-05 15:14:19 -04:00
GPBExtensionInternals.h Beta quality drop of Objective C Support. 2015-06-08 17:17:22 -04:00
GPBExtensionInternals.m Add more warnings to for the ObjC runtime build 2016-05-25 16:42:31 -04:00
GPBExtensionRegistry.h Fixes extra whitespace on generated comments. () 2016-08-12 14:44:03 -04:00
GPBExtensionRegistry.m Fix ExtensionRegistry copying and add tests. 2017-05-17 14:51:02 -04:00
GPBMessage_PackagePrivate.h Work around strange error with atomic and swift under Xcode 8.3.3. 2018-01-31 16:57:53 -05:00
GPBMessage.h ObjC: Document the exceptions on some of the writing apis. 2017-06-19 10:33:45 -04:00
GPBMessage.m Work around strange error with atomic and swift under Xcode 8.3.3. 2018-01-31 16:57:53 -05:00
GPBProtocolBuffers_RuntimeSupport.h Trim imports for bundled generated protos. 2018-04-02 09:54:29 -04:00
GPBProtocolBuffers.h Better support for using the proto library from a framework. 2016-05-24 09:25:02 -04:00
GPBProtocolBuffers.m Don't #import the .m files. 2016-07-07 08:45:18 -04:00
GPBRootObject_PackagePrivate.h Beta quality drop of Objective C Support. 2015-06-08 17:17:22 -04:00
GPBRootObject.h Migrating documentation of the ObjectiveC runtime code to appledoc. () 2016-08-08 10:15:02 -04:00
GPBRootObject.m Remove unreferenced 'GPBMessageSignatureProtocol' class. 2017-11-14 15:16:04 -08:00
GPBRuntimeTypes.h Migrating documentation of the ObjectiveC runtime code to appledoc. () 2016-08-08 10:15:02 -04:00
GPBUnknownField_PackagePrivate.h Expose the initializer for unknown fields. 2017-07-05 11:16:34 -04:00
GPBUnknownField.h Expose the initializer for unknown fields. 2017-07-05 11:16:34 -04:00
GPBUnknownField.m Add header need for module maps. 2018-08-06 18:41:22 -04:00
GPBUnknownFieldSet_PackagePrivate.h Alpha 1 drop of Google's Objective C plugin and runtime support for protobufs. 2015-05-06 13:19:14 -04:00
GPBUnknownFieldSet.h Migrating documentation of the ObjectiveC runtime code to appledoc. () 2016-08-08 10:15:02 -04:00
GPBUnknownFieldSet.m Remove the custom key functions and just use the system provided defaults. 2016-09-19 13:12:35 -04:00
GPBUtilities_PackagePrivate.h Add casts to removed undefined behaviors around shifts. 2018-01-31 12:36:54 -05:00
GPBUtilities.h Add GPBMessageDropUnknownFieldsRecursively() and tests. 2017-02-23 15:04:06 -05:00
GPBUtilities.m Work around strange error with atomic and swift under Xcode 8.3.3. 2018-01-31 16:57:53 -05:00
GPBWellKnownTypes.h Timestamp helper fix, Duration helper cleanup. 2017-01-12 19:33:25 -05:00
GPBWellKnownTypes.m Timestamp helper fix, Duration helper cleanup. 2017-01-12 19:33:25 -05:00
GPBWireFormat.h Validate the tag numbers when parsing. () 2016-06-29 09:51:13 -04:00
GPBWireFormat.m Validate the tag numbers when parsing. () 2016-06-29 09:51:13 -04:00
README.md Remove/replace travis references () 2018-07-22 17:14:24 -07:00

Protocol Buffers - Google's data interchange format

Build status Build status Build status Build status

Copyright 2008 Google Inc.

This directory contains the Objective C Protocol Buffers runtime library.

Requirements

The Objective C implementation requires:

  • Objective C 2.0 Runtime (32bit & 64bit iOS, 64bit OS X).
  • Xcode 8.0 (or later).
  • The library code does not use ARC (for performance reasons), but it all can be called from ARC code.

Installation

The distribution pulled from github includes the sources for both the compiler (protoc) and the runtime (this directory). After cloning the distribution and needed submodules (see the src directory's README), to build the compiler and run the runtime tests, you can use:

 $ objectivec/DevTools/full_mac_build.sh

This will generate the src/protoc binary.

Building

There are two ways to include the Runtime sources in your project:

Add objectivec/*.h, objectivec/google/protobuf/*.pbobjc.h, and objectivec/GPBProtocolBuffers.m to your project.

or

Add objectivec/*.h, objectivec/google/protobuf/*.pbobjc.h, objectivec/google/protobuf/*.pbobjc.m, and objectivec/*.m except for objectivec/GPBProtocolBuffers.m to your project.

If the target is using ARC, remember to turn off ARC (-fno-objc-arc) for the .m files.

The files generated by protoc for the *.proto files (*.pbobjc.h and *.pbobjc.m) are then also added to the target.

Usage

The objects generated for messages should work like any other Objective C object. They are mutable objects, but if you don't change them, they are safe to share between threads (similar to passing an NSMutableDictionary between threads/queues; as long as no one mutates it, things are fine).

There are a few behaviors worth calling out:

A property that is type NSString* will never return nil. If the value is unset, it will return an empty string (@""). This is inpart to align things with the Protocol Buffers spec which says the default for strings is an empty string, but also so you can always safely pass them to isEqual:/compare:, etc. and have deterministic results.

A property that is type NSData* also won't return nil, it will return an empty data ([NSData data]). The reasoning is the same as for NSString not returning nil.

A property that is another GPBMessage class also will not return nil. If the field wasn't already set, you will get a instance of the correct class. This instance will be a temporary instance unless you mutate it, at which point it will be attached to its parent object. We call this pattern autocreators. Similar to NSString and NSData properties it makes things a little safer when using them with isEqual:/etc.; but more importantly, this allows you to write code that uses Objective C's property dot notation to walk into nested objects and access and/or assign things without having to check that they are not nil and create them each step along the way. You can write this:

- (void)updateRecord:(MyMessage *)msg {
  ...
  // Note: You don't have to check subMessage and otherMessage for nil and
  // alloc/init/assign them back along the way.
  msg.subMessage.otherMessage.lastName = @"Smith";
  ...
}

If you want to check if a GPBMessage property is present, there is always as has\[NAME\] property to go with the main property to check if it is set.

A property that is of an Array or Dictionary type also provides autocreator behavior and will never return nil. This provides all the same benefits you see for the message properties. Again, you can write:

- (void)updateRecord:(MyMessage *)msg {
  ...
  // Note: Just like above, you don't have to check subMessage and otherMessage
  // for nil and alloc/init/assign them back along the way. You also don't have
  // to create the siblingsArray, you can safely just append to it.
  [msg.subMessage.otherMessage.siblingsArray addObject:@"Pat"];
  ...
}

If you are inspecting a message you got from some other place (server, disk, etc), you may want to check if the Array or Dictionary has entries without causing it to be created for you. For this, there is always a \[NAME\]_Count property also provided that can return zero or the real count, but won't trigger the creation.

For primitive type fields (ints, floats, bools, enum) in messages defined in a .proto file that use proto2 syntax there are conceptual differences between having an explicit and default value. You can always get the value of the property. In the case that it hasn't been set you will get the default. In cases where you need to know whether it was set explicitly or you are just getting the default, you can use the has\[NAME\] property. If the value has been set, and you want to clear it, you can set the has\[NAME\] to NO. proto3 syntax messages do away with this concept, thus the default values are never included when the message is encoded.

The Objective C classes/enums can be used from Swift code.

Objective C Generator Proto File Options

objc_class_prefix=<prefix> (no default)

Since Objective C uses a global namespace for all of its classes, there can be collisions. This option provides a prefix that will be added to the Enums and Objects (for messages) generated from the proto. Convention is to base the prefix on the package the proto is in.

Objective C Generator protoc Options

When generating Objective C code, protoc supports a --objc_opt argument; the argument is comma-delimited name/value pairs (key=value,key2=value2). The keys are used to change the behavior during generation. The currently supported keys are:

  • generate_for_named_framework: The value used for this key will be used when generating the #import statements in the generated code. Instead of being plain #import "some/path/file.pbobjc.h" lines, they will be framework based, i.e. - #import <VALUE/file.pbobjc.h>.

    NOTE: If this is used with named_framework_to_proto_path_mappings_path, then this is effectively the default to use for everything that wasn't mapped by the other.

  • named_framework_to_proto_path_mappings_path: The value used for this key is a path to a file containing the listing of framework names and proto files. The generator uses this to decide if another proto file referenced should use a framework style import vs. a user level import (#import <FRAMEWORK/file.pbobjc.h> vs #import "dir/file.pbobjc.h").

    The format of the file is:

    • An entry is a line of frameworkName: file.proto, dir/file2.proto.
    • Comments start with #.
    • A comment can go on a line after an entry. (i.e. - frameworkName: file.proto # comment)

    Any number of files can be listed for a framework, just separate them with commas.

    There can be multiple lines listing the same frameworkName incase it has a lot of proto files included in it; and having multiple lines makes things easier to read.

Contributing

Please make updates to the tests along with changes. If just changing the runtime, the Xcode projects can be used to build and run tests. If your change also requires changes to the generated code, objectivec/DevTools/full_mac_build.sh can be used to easily rebuild and test changes. Passing -h to the script will show the addition options that could be useful.

Documentation

The complete documentation for Protocol Buffers is available via the web at:

https://developers.google.com/protocol-buffers/