matomo-org / matomo-sdk-ios

Matomo iOS, tvOS and macOS SDK: a Matomo tracker written in Swift
MIT License
390 stars 164 forks source link

Compiler Error #208

Closed mkrajcir closed 6 years ago

mkrajcir commented 6 years ago

I tried to use Piwik iOS SDK 4.4. Unfortunatelly I got a Compiler Error with Xcode 9.1.

Pods/PiwikTracker/PiwikTracker/Application.swift:4:27: 'bundleDisplayNameForCurrentApplication' is inaccessible due to 'private' protection level

Solution: private methods from extensions should be fileprivate.

brototyp commented 6 years ago

Hi @mkrajcir, thanks for your report. Unfortunately I wasn't able to reproduce your issue. What exactly can be done to reproduce it? The iOS Example in the repository works well and doesn't show this issue. Thanks in advance!

AndreaGer commented 6 years ago

@brototyp I get the same issue. Just install the latest version of the pod and try to compile it. You don't actually need to implement the code to get the issue. 4.4 is useless as of now.

mrommel commented 6 years ago

Same for me - I was on pod 'PiwikTracker', '4.2.0' and updating to pod 'PiwikTracker', '4.4.0' gives a lot of build errors:

/myfunnyapp/Pods/PiwikTracker/PiwikTracker/Application.swift:4:27: error: 'bundleDisplayNameForCurrentApplication' is inaccessible due to 'private' protection level let displayName = bundleDisplayNameForCurrentApplication() ^ /myfunnyapp/Pods/PiwikTracker/PiwikTracker/Application.swift:30:25: note: 'bundleDisplayNameForCurrentApplication()' declared here private static func bundleDisplayNameForCurrentApplication() -> String? { ^ /myfunnyapp/Pods/PiwikTracker/PiwikTracker/Application.swift:5:20: error: 'bundleNameForCurrentApplication' is inaccessible due to 'private' protection level let name = bundleNameForCurrentApplication() ^ /myfunnyapp/Pods/PiwikTracker/PiwikTracker/Application.swift:35:25: note: 'bundleNameForCurrentApplication()' declared here private static func bundleNameForCurrentApplication() -> String? { ^ /myfunnyapp/Pods/PiwikTracker/PiwikTracker/Application.swift:6:26: error: 'bundleIdentifierForCurrentApplication' is inaccessible due to 'private' protection level let identifier = bundleIdentifierForCurrentApplication() ^ /myfunnyapp/Pods/PiwikTracker/PiwikTracker/Application.swift:40:25: note: 'bundleIdentifierForCurrentApplication()' declared here private static func bundleIdentifierForCurrentApplication() -> String? { ^ /myfunnyapp/Pods/PiwikTracker/PiwikTracker/Application.swift:7:23: error: 'bundleVersionForCurrentApplication' is inaccessible due to 'private' protection level let version = bundleVersionForCurrentApplication() ^ /myfunnyapp/Pods/PiwikTracker/PiwikTracker/Application.swift:45:25: note: 'bundleVersionForCurrentApplication()' declared here private static func bundleVersionForCurrentApplication() -> String? { ^ /myfunnyapp/Pods/PiwikTracker/PiwikTracker/Application.swift:8:28: error: 'bundleShortVersionForCurrentApplication' is inaccessible due to 'private' protection level let shortVersion = bundleShortVersionForCurrentApplication() ^ /myfunnyapp/Pods/PiwikTracker/PiwikTracker/Application.swift:50:25: note: 'bundleShortVersionForCurrentApplication()' declared here private static func bundleShortVersionForCurrentApplication() -> String? {

thorstenstark commented 6 years ago

I can verify this behaviour on Xcode 9.2 with Swift 4. Seems like private is visible to extensions in the same file when it is declared in the declaration. private properties in extensions on the other hand are not visible to the declaration.

See Apples Swift Programming Language documentation for more details.

AndreaGer commented 6 years ago

der ganze thread voller leute aus berlin 😆

brototyp commented 6 years ago

Thanks everyone, I am on the same page as you all. Still I am not sure why I am not able to reproduce this issue. Neither in the iOS Example Application in the repository, nor the following way:

The project is Xcode 9.2 and it is Swift 4 but it builds like a charm. I just want to add test so this issue will not happen again. Can anyone reproduce the issue the way I've written it down here? (You can download the test project here)

thorstenstark commented 6 years ago

I think I got the issue: my Podfile still contained the following post install script:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '3.2'
        end
    end
end

When I add this to your test project @brototyp I get the same errors.

brototyp commented 6 years ago

So the issue is, that the SDK is compiled as a Swift 3 Library, while it actually is a Swift 4 Library, right? Does it work if you set the SWIFT_VERSION to 4? If so, I think we found the solution for this issue.

thorstenstark commented 6 years ago

I removed the whole post install script, as there weren't any other pods in the app and that worked. As not setting a Swift version explicitly makes the pod using the projects Swift version, yes, this was the solution.

brototyp commented 6 years ago

Lovely. Thanks for checking that. I will close this thread for now. Please comment if you encounter any other issues.

satheeshwaran commented 6 years ago

For users who have not upgraded their projects to Swift 4.0,

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '4.0'
        end
    end
end