DaveWoodCom / XCGLogger

A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FileDestination.swift:95:92: Cannot convert value of type '[FileAttributeKey : Any]?' to expected argument type '[String : Any]?'

winzig opened this issue · comments

In the 6.0.0 version, I'm receiving an error when building in Xcode 9:

XCGLogger/Destinations/FileDestination.swift:95:92: Cannot convert value of type '[FileAttributeKey : Any]?' to expected argument type '[String : Any]?'

My app is written in Swift 3.2.

The line referenced is:

https://github.com/DaveWoodCom/XCGLogger/blob/master/Sources/XCGLogger/Destinations/FileDestination.swift#L95

It does appear to be that that line isn't compatible with Swift 3.2.

Hi. Use XCGLogger 5.0.5 for Swift 3.2. 6.0.0 is for Swift 4.0.

They are functionally the same, 6.0.0 just updates syntax for Swift 4

OK, gotcha, thank you.

Hi @winzig and @TannerJuby1 (via #233).

I've done some more testing with this, and if you're using CocoaPods, it seems that pod update will change the SWIFT_VERSION setting for each target in your pod project. So you may have it set to 4.0, then it'll revert to 3.0 and you'll get the above errors again.

I've just released 6.0.1 that adds a setting to the podspec that specifies the SWIFT_VERSION for XCGLogger. However, it seems that CocoaPods (1.3.1 at least) will still set a default version that overrides it. So, I've created a post_install hook you can add to your project's podfile that will correct the SWIFT_VERSION.

post_install do |installer|
    installer.pods_project.targets.each do |target|
        if ['SomeTarget-iOS', 'SomeTarget-watchOS'].include? "#{target}"
            print "Setting #{target}'s SWIFT_VERSION to 4.0\n"
            target.build_configurations.each do |config|
                config.build_settings['SWIFT_VERSION'] = '4.0'
            end
        else
            print "Setting #{target}'s SWIFT_VERSION to Undefined (Xcode will automatically resolve)\n"
            target.build_configurations.each do |config|
                config.build_settings.delete('SWIFT_VERSION')
            end
        end
    end

    print "Setting the default SWIFT_VERSION to 3.2\n"
    installer.pods_project.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '3.2'
    end
end

You may need to tweak that, replace SomeTarget-iOS etc with other targets that should be 4.0 and don't specify the version in their podspec.

Let me know if that helps.

does this problem still exist?
I updated my pods and XCGLogger was updated to 6.0.4. getting the same error message:

"Cannot convert value of type '[FileAttributeKey : Any]?' to expected argument type '[String : Any]?'"

at code line:

` private func openFile() {
guard let owner = owner else { return }

    if logFileHandle != nil {
        closeFile()
    }

    guard let writeToFileURL = writeToFileURL else { return }

    let fileManager: FileManager = FileManager.default
    let fileExists: Bool = fileManager.fileExists(atPath: writeToFileURL.path)
    if !shouldAppend || !fileExists {
        fileManager.createFile(atPath: writeToFileURL.path, contents: nil, attributes: fileAttributes)
    }

...
`
in:
// FileDestination.swift

any updates on what to do?

hi @DaveWoodCom can you please help that how to add target name in the above script you had given... e.g if my one of the target name is "ProjNameWatchApp" then how could I add it in above script ? I had added like below

if ['ProjName', 'ProjNameWatchApp'].include? "#{target}" print("Setting #{target}'s SWIFT_VERSION to 4.0\n") else print("Setting #{target}'s SWIFT_VERSION to Undefined (Xcode will automatically resolve)\n") end
here the loop always goes in else condition and my every pod Swift_version is set like below
Setting AFNetworking's SWIFT_VERSION to Undefined (Xcode will automatically resolve) Setting APNumberPad's SWIFT_VERSION to Undefined (Xcode will automatically resolve)

Can you please help me how to solve the XCGLogger in FileDestination.swift file by solving this issue

Thanks

The problem still exists in Xcode 10.2 swift 4.2 version, trying to upgrade it XCGLogger 6.1.0. Please do a permanent fix.

I think the solution to this might be to add:

  spec.swift_version = '4.2'

into the XCGLogger .podspec.