-
Notifications
You must be signed in to change notification settings - Fork 154
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
GRMustache interferes with the AnyObject subscript (Cast from 'MustacheBox!' to unrelated type 'String' always fails) #12
Comments
Hello @crarau Things are indeed weird: let dict:[String: AnyObject] = ["key": "value"]
let anyObject = dict as AnyObject
let v2 = anyObject["key"] // Alt-click on v2: MustacheBox!
print(v2.dynamicType) // Prints ImplicitlyUnwrappedOptional<MustacheBox>
print(v2.value) // Crash
let v3 = anyObject["key"]! // Alt-click on v3: MustacheBox
print(v3.dynamicType) // Prints _NSContiguousString So we're facing a paticularly crazy Swift bug. After refactoring the subscript functions declared by GRMustache, I could spot the origin of the problem: final public class MustacheBox : NSObject {
public subscript (key: String) -> MustacheBox
} OK, so:
Thanks again for opening thise issue, stay tuned! |
For what it's worth, Xcode 7.1 beta 3 (7B85) still has the issue. |
Next release is coming shortly. |
Please update to GRMustache v0.11.0. Oh, and please stick to tagged versions. Forget about branches, because they may contain unstable code. |
rdar://23122734 (http://openradar.appspot.com/radar?id=4952382538514432) |
Before using Mustache.swift the codebase was accessing the subscript of an AnyObject (that was a Dictionary underneath). I know it's not a best practice but this was working.
After adding Mustache, it seems that the subscript access is override and a MustacheBox is returned.
I looked at the MustacheBox and I can't figure out why this is happening.
We easily fixed the issue by not treating the Dictionary like an AnyObject but like an Dictionary. But I'd like to understand why MustacheBox interfered with the AnyObject subscript.
Thanks for the library, it's so useful!
Note: I'm using the Swift2 branch
The text was updated successfully, but these errors were encountered: