ameingast / cocoaimagehashing

Perceptual Image Hashing for macOS, iOS, tvOS and watchOS
Other
262 stars 66 forks source link

Can this library be used from Swift on macOS? #9

Closed ejsarge closed 7 years ago

ejsarge commented 7 years ago

Great looking library - I think it would solve a problem I have very well.

I'm trying to use it from Swift and I can't get it to link. (I normally program in another language so I don't know what I'm doing here.) I followed the instructions to install CocoaPods and add this library. I also added CocoaImageHashing to the Linked Frameworks and Libraries.

When I attempt to run the default Hello World swift I get

dyld: Library not loaded: @rpath/CocoaImageHashing.framework/Versions/A/CocoaImageHashing
Referenced from: /Users/sarge/Library/Developer/Xcode/DerivedData/PHashTest-cdongczzcrynrfclysczwalanrlq/Build/Products/Debug/PHashTest
Reason: image not found
(lldb)

If I remove the use_frameworks! from the Podfile I get

Framework not found CocoaImageHashing

My Podfile

platform :osx, '10.12'
target 'PHashTest' do
    use_frameworks!
    pod 'CocoaImageHashing', :git => 'https://github.com/ameingast/cocoaimagehashing.git'```
end

Many thanks for any help or documentation updates you might provide.

ameingast commented 7 years ago

The combination of Cocoapods and Objective-C works, but I'm not sure about Swift and Cocoapods.

I'm currently using CocoaImageHashing in a large macOS project (100% Swift) through Carthage and it works just fine.

nicoara commented 7 years ago

Any update on this? I have the following problem trying to use the library in Swift: http://stackoverflow.com/questions/42394692/swift-use-of-undeclared-type-for-objective-c-library?noredirect=1#comment71937205_42394692

-- update: solved the issue. Cocoapods does not install this library correctly in Xcode 8.2. At Target level, in Build Settings -> Search Paths -> Header Search Paths: there is a path generated by Cocoapods that does not correspond to any actual folder structure: "${PODS_ROOT}/Headers/Public/CocoaImageHashing" when the /Headers/Public structure does not exist. I removed that and remained with ${PODS_ROOT}/CocoaImageHashing , corresponding to the folder Projectname/Pods/Pods-Projectname.debug.xcconfig and now the library was seen. as an aside, the #import <CocoaImageHashing/CocoaImageHashing.h> is imported inside the Bridging Header file.

ejsarge commented 7 years ago

@ameingast Thanks. I tried Carthage and I, too, found it worked just fine too. Perhaps I might suggest the installation instructions in the Readme be updated to include Carthage instructions? This is especially for people new to Swift who don't know the build tool options and just blindly follow what the library says...

The hashing worked great, btw.

ameingast commented 7 years ago

The documentation was updated by @sarah-j-smith.

I'm closing this for now. If there's any more trouble with Swift + Cocoapods, please open another issue.