{"id":263,"date":"2016-12-01T07:26:22","date_gmt":"2016-12-01T07:26:22","guid":{"rendered":"http:\/\/ootips.org\/yonat\/?p=263"},"modified":"2019-10-30T09:28:40","modified_gmt":"2019-10-30T09:28:40","slug":"auto-compile-proto-files","status":"publish","type":"post","link":"https:\/\/ootips.org\/yonat\/auto-compile-proto-files\/","title":{"rendered":"Auto-Compile .proto Files"},"content":{"rendered":"<p><a href=\"https:\/\/developers.google.com\/protocol-buffers\/\" target=\"_blank\" rel=\"noopener noreferrer\">Google&#8217;s protobuf compiler<\/a> with <a href=\"https:\/\/github.com\/apple\/swift-protobuf\" target=\"_blank\" rel=\"noopener noreferrer\">Apple&#8217;s swift plugin<\/a> converts <code>.proto<\/code> definitions to <code>.swift<\/code> implementations.<\/p>\n<p>Instead of converting from the console and then including the generated file in your project, you can include the <code>.proto<\/code> file in your Xcode project, and let Xcode automatically convert it to swift and use the generated file:<\/p>\n<ol>\n<li>Go to your target <strong>Build Rules<\/strong>.<\/li>\n<li>Click the <strong>+<\/strong> above to add a custom rule: <strong>Sources with names matching:<\/strong> <code>*.proto<\/code>.<\/li>\n<li>Use the following script:\n<p><code>protoc --proto_path=\"$INPUT_FILE_DIR\" --swift_out=\"$DERIVED_FILE_DIR\" \"$INPUT_FILE_PATH\"<\/code><\/li>\n<li>Add to <strong>Output Files<\/strong> using the <strong>+<\/strong> below:\n<p><code>$(DERIVED_FILE_DIR)\/$(INPUT_FILE_BASE).pb.swift<\/code><\/li>\n<li>Go to <strong>Build Phases<\/strong>, to the <strong>Compile Sources<\/strong> section, and add your <code>.proto<\/code> files to the list.<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-267\" src=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2016\/12\/xcode-proto.png\" alt=\"xcode-proto\" width=\"1566\" height=\"732\" srcset=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2016\/12\/xcode-proto.png 1566w, https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2016\/12\/xcode-proto-300x140.png 300w, https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2016\/12\/xcode-proto-768x359.png 768w, https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2016\/12\/xcode-proto-1024x479.png 1024w\" sizes=\"auto, (max-width: 1566px) 100vw, 1566px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google&#8217;s protobuf compiler with Apple&#8217;s swift plugin converts .proto definitions to .swift implementations. Instead of converting from the console and then including the generated file in your project, you can include the .proto file in your Xcode project, and let &hellip; <a href=\"https:\/\/ootips.org\/yonat\/auto-compile-proto-files\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[7,6,19,17,20],"class_list":["post-263","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-ios","tag-iphone","tag-protobuf","tag-swift","tag-xcode"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2aEUP-4f","_links":{"self":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/comments?post=263"}],"version-history":[{"count":8,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/263\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/media?parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/categories?post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/tags?post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}