Skip to content

How to use cocoalumberjack with Swift #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GuyFran opened this issue Nov 27, 2014 · 59 comments
Closed

How to use cocoalumberjack with Swift #405

GuyFran opened this issue Nov 27, 2014 · 59 comments
Labels
Milestone

Comments

@GuyFran
Copy link

GuyFran commented Nov 27, 2014

Hi.
I've been reading here and there, and I am unsure how to use the framework with swift.

I've seen people aking their own wrappers in swift, but that was quite some months ago.

Following the issues in there, my understanding is that there's an official swift wrapper for using cocoalumberjack.

Having retrieved the lib with cocoapods , the beta 4 from 2.0.0, I still don't see any swift class there, and none of the example projects uses a swift also.

So I'm kinda confused how to make that work with the "official" means.

Any light that you can shed on this ?

Thx

@rivera-ernesto
Copy link
Member

I think that for now you should install the standard Objective-C library with CocoaPods and then manually import the CocoaLumberjack.swift wrapper, as CocoaPods doesn't yet support Swift.

I will just make sure that the wrapper is preserved in the directory as currently it gets deleted by CocoaPods.

@rivera-ernesto
Copy link
Member

Also there is #400.

@GuyFran
Copy link
Author

GuyFran commented Nov 27, 2014

I have added , as usual, the lib pod to my podfile. It's there.

Now I've manually imported the CocoaLumberjack.swift to my project (in swift).
But I get a compile error : import CocoaLumberjack -> "No such module"

Do I need to add on something ? Tweak the bridging header file ?

@palewar
Copy link

palewar commented Nov 27, 2014

@crazykoala May be this will help - http://swiftwala.com/cocoapods-is-ready-for-swift/

@GuyFran
Copy link
Author

GuyFran commented Nov 28, 2014

I have followed the procedure indicated, and it's working for alamofire and swiftjson.

Not working for cocoalumberjack though.
I tried to paste

pod 'CocoaLumberjack', :git => "https://github.com/CocoaLumberjack/CocoaLumberjack.git", :branch => "podspec"

in my Podfile. No success. What would be the proper line for the podfile for this library ?

@palewar
Copy link

palewar commented Nov 28, 2014

@crazykoala Give this a try:

pod 'CocoaLumberjack', :git => "https://github.com/ValCapri/CocoaLumberjack.git"

@GuyFran
Copy link
Author

GuyFran commented Nov 28, 2014

Ok this retrieves the pod with the .swift wrapper.

But still it doesn't compile afterwards.

  • If I uses "pod install" to retrieve my pods, i get this error "import CocoaLumberjack : No such module'
  • If I use "bundle exec pod install" to retrieve the pods , the .h of the other pods are not found. Erf.

Really no luck :/

@rivera-ernesto
Copy link
Member

@palewar Maybe also include the :commit.

@GuyFran
Copy link
Author

GuyFran commented Nov 28, 2014

@rivera-ernesto , is there such a way with the "official" repo ?

Or is there a step by step guide on how to include the lib with a swift project ? (with or without cocoapods)

@rivera-ernesto
Copy link
Member

Yes. You just set the official repository in the :git part.

@GuyFran
Copy link
Author

GuyFran commented Dec 1, 2014

I see , but I'm actually trying to get it working with Swift.

@palewar , when I use this branch, I get the swift class, but I get an error upon compile : " No such module CocoaLumberjack" on the import line.

Could you help me fix this ?

@rivera-ernesto
Copy link
Member

Closing this in favor of #383.

@palewar
Copy link

palewar commented Dec 1, 2014

@crazykoala Probably a silly question, but are you using .xcworkspace file to open and build project? Please share your Podfile with me or your github URL if it's a public project and I will see if I can do anything to get it working.

@rivera-ernesto
Copy link
Member

I will try to set up a proper Swift Demo project.

@GuyFran
Copy link
Author

GuyFran commented Dec 1, 2014

@palewar yes , sure I am using the workspace.

@rivera-ernesto , a demo with the cocoalumberjack as pod dependency. I'd be very curious to see how it's set up, cause mine fails no matter what i try, Thx

@rivera-ernesto
Copy link
Member

Gonna make one tomorrow.

@nateuni
Copy link

nateuni commented Jan 28, 2015

What was the outcome here guys? I am having the same issue.

@wimhaanstra
Copy link

Yup, got the same question. I know this ticket is closed, but I got the same "No such module" error.

@rivera-ernesto
Copy link
Member

CocoaPods is very close to releasing Swift support. Does anyone wants to give a try to the betas?

Sadly I didn't get the time to work on it.

Let's reopen this in the mean time.

@linkoubian
Copy link

@thejeraldo thanks, your comments help me a lot:-)

@leolelego
Copy link

Somebody can make a summary on how to use Cocoalumberjack with SWIFT 2.0 ?

@johndpope
Copy link

I created a test project here> https://github.com/johndpope/CocoaLumberjack-Swift

pod 'CocoaLumberjack/Swift', :git => 'https://github.com/CocoaLumberjack/CocoaLumberjack.git', :branch => 'swift_2.0'

I had troubles with the original Formatter class in this repo - so feel free to grab my one.

import UIKit
import CocoaLumberjack

let ddloglevel = DDLogLevel.Verbose

private func printSomething() {
DDLogVerbose("Verbose");
DDLogDebug("Debug");
DDLogInfo("Info");
DDLogWarn("Warn");
DDLogError("Error");
}

    @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    let formatter = Formatter()
    DDTTYLogger.sharedInstance().logFormatter = formatter

    DDLog.addLogger(DDTTYLogger.sharedInstance())

    DDLogVerbose("Verbose");
    DDLogDebug("Debug");
    DDLogInfo("Info");
    DDLogWarn("Warn");
    DDLogError("Error");

    printSomething()

    defaultDebugLevel = ddloglevel

    printSomething()

    return true
}

@leolelego
Copy link

Thanks a lot John ! This was be very helpfull ! This little exemple save my night !

@gooner22
Copy link

@johndpope thanks! extremely helpful!

@nigilan
Copy link

nigilan commented Aug 6, 2015

I installed PubNub which has dependency of CocoaLumberjack using CocoaPods. It installed fine and CocoaLumberjack.swift is created without trouble.

@pavm035
Copy link

pavm035 commented Aug 11, 2015

@bpoplauschi Is still an issue in master branch? it would be great help if we get out of this workaround?

@bpoplauschi
Copy link
Member

I'm not sure. You should try for yourself :)

@johndpope
Copy link

I've been building an objective-c to swift converter.
Ping me if you want to check out source code. http://objc2swift.io

@pavm035
Copy link

pavm035 commented Aug 12, 2015

Thanks @johndpope is it beta? and will it work as original Lumberjack(Objective-c) version?

@johndpope
Copy link

It's early beta - but stable. Fire up the app - point it to an existing repository. It will trawl through .m source files en masse and translate to .swift files.

Defect list is growing - but I have been collecting them.
https://rink.hockeyapp.net/recruit/acc09efcee42415aa406036f3a24ab0b

@johndpope
Copy link

this is a sample repo - from a few weeks back.

johndpope/EZForm@21c27bd

@pavm035
Copy link

pavm035 commented Aug 13, 2015

Thanks a lot i will play with this in sometime

@KingWu
Copy link

KingWu commented Aug 23, 2015

Just run the demo project.
https://github.com/johndpope/CocoaLumberjack-Swift

i get compile error. any idea?

:0: error: could not build Objective-C module 'CocoaLumberjack'
0 swift 0x00000001105b22b8 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x00000001105b2794 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff8f37ef1a _sigtramp + 26
3 libsystem_platform.dylib 0x00007fff4fd67198 _sigtramp + 3231613592
4 swift 0x000000010fe9a4e6 main + 1814
5 libdyld.dylib 0x00007fff87e235c9 start + 1
Stack dump:

@bpoplauschi
Copy link
Member

I just tested with the https://github.com/johndpope/CocoaLumberjack-Swift project and after a few updates, everything worked fine. I have created a PR with the updates. I think our current Swift branch looks good and can be merged into master.

@bpoplauschi
Copy link
Member

I have just released a Beta 2.1.0 version via CocoaPods including the Swift 2.0 support (also available in the latest master). Please test it and tell us if it works as expected.

@jpshelley
Copy link

@bpoplauschi Is there any documentation around swift support yet? such as setup and usage?

@rivera-ernesto
Copy link
Member

I think that would have to come from contributors through pull requests ;)

@jpshelley
Copy link

@bpoplauschi @rivera-ernesto with swift 2.0 support in master, do we still have to manually import the swift wrapper file (CocoaLumberjack.swift)?

@johndpope
Copy link

Thx @bpoplauschi I've merged that request.

fyi - it's possible to use bundler to manage dependencies around which cocoapods version a project should use. As swift has been in a state of flux / one week project may work - the next - broken.

I don't have time to add to project - but I highly recommend this if you're working in teams with different cocoapod / xcode versions.
http://www.sm-cloud.com/rvm-bundler-cocoapods-happy-dependency-management/

@jpshelley jpshelley mentioned this issue Oct 13, 2015
@bpoplauschi
Copy link
Member

I think we still need to write the documentation part. Anyone can help with that?

@rivera-ernesto
Copy link
Member

Closing this with the following answer (Cocoapods):

pod 'CocoaLumberjack/Swift', :tag => '2.1.0-beta'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests