groue / GRMustache.swift

Flexible Mustache templates for Swift

Home Page:http://mustache.github.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boxed NSObjects fail for Cocoapods installation

kylealanhale opened this issue · comments

When installing the framework via Cocoapods, NSObject subclasses aren't properly boxed, due to the compiler conditional in Box.swift.

Here's a temporary workaround hook for a project's Podfile:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        if target.name == "GRMustache.swift"
            target.build_configurations.each do |config|
                config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['$(inherited)', '-DOBJC']
            end
        end
    end
end

@kylealanhale Thank you for the notice, let me have a look.

Damned, I forgot this issue for the 2.0.0 release.

@kylealanhale, @AMTourky Do you know what is needed in the podspec for the OBJC swift flag to be automatically set?

Currently having this issue... Thought I'd have to manually override for boxed items! Any update on this?

@groue @sahandnayebaziz It's been a while, but I'm not sure that it was a problem with the podspec; if so, maybe the modification I made to my podfile in the original report will be helpful. But if I'm remembering correctly, it would be better to remove the OBJC check and handle that scenario differently. (Also, it looks like the code in question was moved during the 2.0.0 refactor; it's now here.)

I've lost some hours debugging this when switching from the ObjC version GRMustache to GRMustache.swift for rendering of my NSObject, so I propose at least adding a note to the README with #71.

Same problem also happens when using as Swift package, probably not fixable because in a Swift package it's not possible to have Obj-C source files.

But maybe GRMustacheKeyAccess could be rewritten in Swift now? At least the problematic example in the implementation note from here now works in Swift:

// IMPLEMENTATION NOTE
//
// This code comes from Objective-C GRMustache.
//
// It is still written in Objective-C because
// +[GRMustacheKeyAccess isSafeMustacheKey:forObject:] used to need the
// [[object class] safeMustacheKeys] for classes that would conform to the
// now removed GRMustacheSafeKeyAccess protocol.
//
// Swift would not let us do that (see example below):
//
// ::
//
// import Foundation
//
// @objc protocol P {
// static func f() -> String
// }
//
// class C : NSObject, P {
// class func f() -> String { return "C" }
// }
//
// // Expect "C", But we get the error:
// // accessing members of protocol type value 'P.Type' is unimplemented
// (C.self as P.Type).f()
//

Screen Shot 2020-02-07 at 13 54 42

Unfortunately I'm not able to do it ATM.