Google Protocol Buffers on iOS/Objective-C - objective-c

I need help to configure/use protobuf in Objective-C for a iOS app.
I've tried all but I keep getting errors on xcode. Did anyone manage to make protobuf work well in Objective-C/iOS?

I have used it to some extent on iOS, and with metasyntactic's extension, it works really well. I even managed to get the code generation as a custom build step in Xcode. We switched to Thrift for our project (for other reasons), so my apologies if some details below are wrong, but in general this is how to do it.
In Xcode 4.2, open the target properties, go to the "Build Rules" tab and create a new build rule for "*.proto" files
In "Using:", choose "custom script" and use a script like this:
protoc --plugin=/usr/local/bin/protoc-gen-objc $INPUT_FILE_PATH --objc_out=$DERIVED_FILES_DIR
In Output files, add the generated files (there should be two files, $(INPUT_FILE_BASE).pb.m and $(INPUT_FILE_BASE).pb.h.
Add the .proto files to your project.

Related

How do I include Scintilla in an XCode 3.2.5 project?

I downloaded Scintilla, built and ran ScintillaTest. That worked (almost) fine. Now, I want to include Scintilla in a new project, but can't seem to figure out how to. I tried ctrl-clicking my target and selecting Add Existing Framework..., then Add Other... and finally file located at scite337/scintilla/cocoa/ScintillaFramework/build/Release/Scintilla.framework (obviously I omitted the first part of the path).
After I did this I just added an #import statement in the AppDelegate of my further untouched new project. Upon hitting Cmd+R it says ScintillaView.h: no such file or directory...
I thought that if I added the framework to my only target it would pass the location of the header files to the compiler (and preprocessor). Obviously it doesn't, so I assume I'll have to add the paths of the header files (and maybe other files) to the Build Settings, but there are lots of Build Settings, so I don't have a clue where.
If you don't have access to XCode 3.2.x, please leave how you'd do it in a newer version. I've found a lot of information on other XCode matters for higher versions did that work well in XCode 3.2.5 too (with a little bit of searching for menu items and settings panels).
By looking at the ScintillaTest XCode project I discovered how it works: you have to import the XCode project called ScintillaFramework, which is the file named ScintillaFramework.xcodeproj (obviously). But that isn't enough, after that XCode still can't find the header files in the framework. I looked at the build settings in the ScintillaTest project and found 'Header Search Paths' set to ../../. Setting this failed in my project, it had to be one directory less back: ../. No I just need to get the compiler to accept the C++ constructs in the Scintilla framework.
Update:
Strangely, this stopped working. I do not understand it either. So I just right-clicked my target, from there: add existing framework...->add other...->[browse to ScintillaFramework/build/Release/Scintilla.framework]. This works partially, see my newest question.

106 duplicate symbols for architecture armv7

Working on my iPhone app and trying to build for debug and I get "106 duplicate symbols for architecture armv7"?
I am using the .workspace file because I am trying to use CocoaPods. If I don't use the .workspace and instead use the .xcodeproj I don't get the error, but then I get missing -lPods .
In my project I have the following targets in the Project Navigator.
Pods (blue icon)
MyProject (blue icon)
Restkit.xcodeproj (blue icon)
... all my files
The issue is that Restkit is making reference to "AFHTTPClient.h" and all the other AF code, but I included it via CocoaPods. I tried deleting the AFNetworking folder from the RestKit library, but apparently the Restkit library can't find the Pods version of AFNetworking?
Is there a way to get RestKit to use the Pods version? If not how do I go about removing Pods from my project?
There is a line in one of your .h files where your wrote
#include "___.m"
instead of
#include "___.h"
So I fixed it. After removing the RestKit version of AFNetworking, from the vendor folder, I added it back by dragging into Xcode. It asks which project I want it used/copied to and this time I selected RestKitTest (or whatever the RestKitTesting is named). It works now. Maybe I selected both RestKit and RestKitTest before, which was wrong?
I also came up with same error. Generally this kind of error occurs due to duplicate classes and xibs in project folder. For Example in my project I had these classes twice ServiceRequest.h/.m. Get rid of duplicate ones and you are good to go.
In Build Phases -> Compile Sources, make sure you don't have the same file added twice.
"Duplicate symbols for architecture" issue occurs in two situations:
You added a .m file twice into your project
You're using a static library (.a file) which already includes some classes that you include into the project.
For fixing any of those cases, check the linker error and look for the .o files that are duplicated (sample: Reachability.o).
Then go to the build phases -> compile sources and search the specified files, if any one appears twice delete one of them, if only appears once it means that the file is also included in one of the static libraries added to your project. Delete it from your list of sources to be compiled and try again.
I saw this error when, I did drag and drop my calabash framework onto xcode and selected add to targets option in the window thats shown. Basically there were two references to files added
I had to remove the calabash framework manually
Right way of doing it
copy to calabash framework to project directory
then go to xcode project
Choose target -> Build phases -> Link Binary With Libraries and add the frame work using + button
I have noticed that duplicate symbols are caused for Google analytics after installing cocoaPods as well. Once I removed one of archives, either libGoogleAnalytics_debug.a or libGoogleAnalytics.a duplication has gone. But obviously if I removed debug one I will not be able to run os simulator and vica versa. I know its not the solution, but at least it could give an idea what could be a solution. Will come back to this thread if I will figure out how to have both a files in this case.
Edit:
I was able to solve the issue by upgrading from G analytics version 2 to 3. It has only one library file and I guess this is the reason why we don't get duplicated symbols anymore. I hope it makes sense.

How to install CorePlot framework correctly?

I want to use CorePlot.framework in Mac OS X. However, I cannot install it correctly though it has costed me several hours.
I downloaded it (0.4 version) from google host site, and have tried to put CorePlot.framework in "/Library/Frameworks/" or some other custom places.
I also have added it into "link binary and libraries". unfortunately, the compiler always cannot find "" .
Any one who have some experience can give me some advice to install and use it?
If you check the readme files, you can find the instructions as follows:
Copy the CorePlotHeaders to your Xcode project
Copy libCorePlotCocoaTouch.a to your Xcode project
Add to Other Linker Flags in your target build settings: -ObjC -all_load
Add the QuartzCore framework to the project.
To follow these instructions, create a new blank project and copy the folder (drag and drop) CorePlotHeaders into Xcode. When prompted, be sure to check "copy these files/folders to the source directory".
Next drag the libCorePlayCocoaTouch.a library in the same manner (again, select the checkbox). You should now have the .h files and the .a included in your project.
Now, select your project and choose the "Target" and in the 3rd tab "Build Settings" search for "Other Linker Flags" and add -"ObjC -all_load" without quotes.
Finally, add the QuartzCore framework to your project and you're done.
I've been working with CorePlot today and am rather impressed with it so far. It's not 100% comprehensive but it's good enough for what we need. If you get stuck, be sure to follow the readme instructions and double check everything is setup as needed. I didn't struggle with getting it set up unlike some other libraries so hopefully you should be able to get sorted with minimal fuss :)

Hide code in static library (iOS Obj-C)

I'm working to create an iOS static library that I wish to sell. I've walked through the steps for the initial builds and have generated the .a/.h output.
When I include these files in a separate project, I don't see any way to browse the contents on the .a file.
HOWEVER, when a line of code in my library crashes the app (like I said, it's still in development), the debugger shows the entire class (.m) file to me. What's up with this?
I don't really understand what all goes into static libraries, and I'm not sure I compiled that version for both simulator and device. Could that have something to do with it? If so, could someone explain why?
Thanks!!!
Don't worry, your source code is not included in the archive (.a) file.
Xcode is smart enough to find the source code file on your computer, based on the debugging information embedded in the file. If you build the library using the "Release" configuration (or otherwise modify the build settings so that debugging symbols are stripped) and don't have the source anywhere on the machine, a developer will have to resort to their knowledge of x86 or ARM assembly to figure out how your code works.
By the way:
Since a lot of Objective-C is handled at runtime, a lot of class names and selector names will be visible in your library. That's just how it works. You could try to obfuscate it, but I think your time is better spent writing more useful code to sell.
If you want to give people a static library for iOS development, you'll want to build versions for the iOS Simulator (x86) and the iOS Device (arm) and then use lipo to combine them into a single fat static library. Search around for "lipo xcode fat static library" for different ways to do this. Some solutions are more convoluted than others.
I had the same issue. #benzado is right about what he has mentioned. But I had to strip debugging symbols to solve the issue. To do so, I had to change Build Settings of project library before build as mentioned below.
Select your Target and go to Build Settings. Set
' Strip Debug Symbols During Copy ' to YES
' Debug Information Format ' to 'DWARF with dSYM File'
' Generate Debug Symbols ' to 'NO'
' Symbols Hidden by Default ' to 'YES'
To see what are these for, refer Apple Build Setting Reference
And build the library using the "Release" configuration. This worked for me.
If you have a project for static library with all .m files on your computer then every copy of this library (.a file) will be symbolicated with its .m file while debugging in xCode.
xCode doesn't search for appropriate .m file through all your disk. It knows the place of original project. So if you distribute only library it fully hides your initial code.
To make sure you can copy your library in some new project then clear .m file in library project.
From this moment any attempt to debug methods of library will give empty file on screen.

How do I use a dynamically load library in a command line utility? [duplicate]

This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
using frameworks in a command line tool
Hey,
I've written a command line 'foundation tool' that uses the RegexKit.framework extensively. Everything works when run in Xcode but if I compile the release build and try to run it in Terminal I get the following error:
dyld: Library not loaded: #executable_path/../Frameworks/RegexKit.framework/Versions/A/RegexKit
Closer inspection reveals that the RegexKit.framework bundle is sat in the same directory as my executable file... I've done some research and I'm thinking that as command line tools don't use application bundles there's no where for Xcode to copy the framework to. So I'm guessing that I need to compile the framework as a static library and include it in my code... am I right? If so, how do I go about doing this? Is there anything I can do in Terminal to point to the framework externally?
Any help would be very greatly received, I've been banging my head against this for a few days now!
Thanks in advance,
Tom
So... What I did in the end was to recompile the framework with a different Installation Directory (in the Deployment section, under the Build tab in the Target's Info) - I set it to just #executable_path.
I then compiled the framework and replaced the one in my Utilitie's project, I also changed the Copy Files build phase to copy the framework to "Executables" rather than Frameworks.
The good news is that this fixes my original problem - but obviously the framework has to be in the same directory as the executable.
So this got me unstuck but I'd still love to know how to compile RegexKit.framework statically!
You shouldn't be installing the framework in the Executable folder of your bundle. It should be in the Frameworks folder. You need a Copy Files phase in your project that copies the framework and you need to set the Destination to "Frameworks". "Copy only when installing" should be unchecked.
When testing this, you should make sure you perform a clean build. I typically delete the build folder rather than using Xcode's Clean menu option since it's quicker and more comprehensive.
Also: you cannot statically link to a framework. If you want to statically link to something, it needs to be a static library so in this case, you'd need to hack about with RegexKit. Bear in mind that static libraries cannot contain resources, whereas Frameworks, being bundles, can.