Can't build Swift app including Objective-C Tesseract library - ios

I am trying to utilize the features of Tesseract OCR for an iOS app, and cannot even seem to get it going. I have followed the installation instructions to the tee and have still been unable to get it built correctly.
I have used CocoaPods to integrate Tesseract into my project, and that seems to be working fine, but, I am unsure of exactly what to put into my bridging header. There are over 50 header files in the Tesseract portion of the project, and it doesn't seem like I should need to add each individually into the bridging header.
With copy and pasting the basic code from the instructions into my project, I get a few errors:
1) /Users/kade/Documents/tesseract/tesseract/ViewController.swift:19:30:
Type 'ViewController' does not conform to protocol 'G8TesseractDelegate'
corresponds with this line of code:
tesseract.delegate = self;
2) if I comment this line out, the build succeeds, but then breaks upon execution of the following line:
tesseract.charWhitelist = "01234567890";
I believe this to be a bridging header issue because I have imported a file and fixed a previous error, but I'm not sure which Objective-C header file will include all of them.

Rookie mistake, I just figured it out.
I needed to include: ", G8TesseractDelegate" at the class declaration.
Silly me!
I hope this helps anyone who may be experiencing something similar! :)

Related

Cannot find protocol declaration for *** in my 'MyApp-Swift.h'

I am working on a project that up to now, despite the mess, it was working ok. Today, believe it or not, I have been updating it to Swift 5.
The project has iOS and tvOS targets as well as frameworks, tests, and top selves extensions. The project also was started using Objective-C and over the years has become 90% Swift.
I am not sure at what point something went wrong but, when compiling, I get the following error for all my top self extensions (mostly all tvOS Targets).
I have found similar questions but I can't understand whats going on.
Any ideas?
You are probably missing an import StoreKit in the Swift files that define IAPHelper. Sometimes this gets imported transitively, and Swift doesn't necessarily need it, but the Swift bridging header does.
Ultimately you need to make sure there's an ObjC #import StoreKit; that is evaluated before this line of code.
First, I have to thank Rob for his tips. I wish he could get the points!
After troubleshooting with the tips provided:
Add StoreKit to your linked frameworks list. -> Didn't work
#import StoreKit; before #import <...-Swift.h> -> Showed error use of #import when modules are disabled
I also saw that "...-Swift.h" was only declared in the Build settings of my "...Topself" targets. Still quite unsure why as I would have thought the whole project still have ObjC dependencies... Still quite new to this challenge.
Furthermore, If I unfold the error I could see that there was some kind of error trying to find "...-Swift.h" file.
At this point, I remembered that I am using cocoapods (I don't like you, you don't like me relationship) and I hated to see the warning "...Overrides Enable modules (C - Objective-C)" so I set it to default for the whole project.
Turns out that that for all "...TopSelf" targets, the default value is NO.
By Overriding Enable modules (C - Objective-C) to YES, clean, and build, everything started working again.

Importing CocoaPod into Swift Playground Produces Expression Failed to Parse Error

I have several private pods that I'm already using successfully in my project. I added a Swift playground to the workspace (not to the project), and I've added an import Foo statement to the top of the playground.
Autocomplete is working for my pod modules, so things seem to be set up correctly. However, I'm getting this very obscure error:
expression failed to parse, fixed expression suggested:
#sourceLocation(file: "Foo.playground", line: 1)
It doesn't matter which line I put my import statement on; it always refers to line 1.
There is notably some Obj-C code in the framework that’s being imported. I’m not sure if that matters or not since it’s callable from the Swift in my app.
Any help would be appreciated!
Update (7/21/19): Still haven't been able to resolve this, but I was able to confirm that a much simpler Obj-C library is callable from a playground. So, it's just the complex one I was trying to call initially. Since this is proprietary, there's not a lot of info I can share, but if anyone has suggestions on what to try (or what I can genericize, extract, and share here), I'm happy to take a stab at it and update you. Thanks!

Objective C - Swift Bridging issue Xcode 6.3 -Screenshot provided-

So, I found myself craving a framework to replicate iOS 6 folders animation. Luckily I found one called JWFolders, which is pretty neat and useful, but my problem is the following:
I am doing my program in Swift, in Xcode 6.3, I imported the header file to the bridging thingy in the swift compiler settings, and as long as I don't try to use anything from that framework, it doesn't complain, but as soon as I try to use it and compile I get the errors shown in the image below.
(even with a simple declaration like this)
var folder = JWFolders()
So, If anyone was wondering, I got it working. I contacted the developer and asked for help, and he nicely told me I was forgetting to add the source code files ".m" to the source compiling files.
After that it worked.

Adding Chipmunk Files to XCode NSObjCRuntime NSZone Parse Issue

Im working on SpaceViking project from Ray Wenderlich's Cocos2D Book and the project has worked fine so far. Near the end we are told to add Chipmunk files to the Xcode project and compile & run to test everything is fine without adding any new code yet.
As soon as I do that I get many Parse Issue errors coming from NSZone, NSObject and NSObjCRuntime which I don't get otherwise.
Can anyone help me out on this one? It should be an error on some of the added files. How do I find which one and where the error is being generated so I can fix it?
I would check and make sure the added files are 'typed' correctly by Xcode. Make sure they are set to Objective-C, C++ or C (whatever is appropriate in this case). I used to get tons of errors when importing C files that were mistakenly recognized as Objective-C by Xcode. Just changing the file type would solve most of the compile errors. Just and idea.

Including a C++ header in an Objective-C project yields "Expected * before *" errors

I'm new to Objective C and (unfortunately) also to the project I am working on. I was given a small sample project that refers to work from my predecessors (in C++) and uses it for an iPhone app (Objective C). Rather than extending the sample (it was quick n dirty and I didn't wanna mess around in it) I created a new project from scratch for my stuff. To get it working I need to set up the same links to the previous libraries as the other one, but although in my settings I can't find any differences to the existing project it won't do the trick.
With the help of colleagues and Google I reached this:
1) The project includes two library files, libyid.a and libvrpn.a, via Xcode's "Add files" dialogue. It automatically added the libraries' paths to the Library Search Paths in the Build Settings and the files show in the projects folder structure in XCode.
As far as I can tell this bit seems not to cause problems.
Edit: if i remove these files from the project I get the same errors. I'm now thinking that XCode can resolve the headers, but can't find the implementation and that the libraries may have been there but not been properly set up?
2) One of my custom classes uses
#import "DisplayYid.h"
I added the path to the file's location to the "Header Search Paths" in the Build Settings and it seems to be found alright. (I also added the file via the "Add files" dialogue at some point, but it didn't change anything, so I left it this way)
Now the problem: in
#interface YidController : NSObject {
DisplayYid *myYid;
// (etc. etc.)
}
the identifier "DisplayYid" seems to remain unknown (Error: Expected specifier-qualifier-list before DisplayYid). In addition, all the class definitions in the headers that DisplayYid itself includes yield
error: expected '=', ',', ';', 'asm' or '__attribute__' before '__declspec'
My knowledge here is unfortunately very limited, but it seems to me that XCode can find the headers in question, but somehow would expect the content in a different format/language?
When I had DisplayYid.h included as a file in the project hierarchy I tried to set its file type in the file inspector to "C++ header" (as suggested by some hits I found on Google for my problem), but this doesn't change a thing.
I feel I am missing some tiny but crucial detail, but am not sure-footed enough in any of this to test around further. Hopefully somebody sees my missing link? And sorry if this is too lengthy, I simply tried to include the detailed steps in case this is were the problem lies.
Thanks in advance for your time ;)
EDIT: This question seems to be the same problem, especially the fact that he gets the error multiple times from files simply copied. But none of the suggested solutions seem to work for me.
It's been a while now, but I got hold of the guy who worked on this previously. It took him an hour, but he found the missing bit: In the project settings, two compiler flags needed to be set:
-DIOS (defining the flag iOS)
-x objective-c++
From there on everything went fine. Since this was a rather project-related question and solution, should I delete it all together?

Resources