-
Notifications
You must be signed in to change notification settings - Fork 139
Issue when using nested keypaths when compiling with optimization + Swift 2.2 #135
Comments
This looks like a bug in the ExtensionDictionary valueForKeyPath method. I'll submit a pull request - unfortunately testing for it is pretty difficult as it only occurs when optimizations are switched on. This causes a crash when trying to remove an element from the keys array - but it doesn't crash when not optimized. |
@tholo has provided some additional context:
|
I did come up with a (not very pretty) workaround... ---Sources/ExtensionDictionary.swift 2016-03-29 11:11:46.000000000 -0700
+++ Sources/ExtensionDictionary.swift 2016-04-01 11:54:02.000000000 -0700
@@ -49,11 +49,9 @@
guard let value = self[first] as? AnyObject else {
return nil
}
-
- keys.removeAtIndex(0)
-
- if !keys.isEmpty, let subDict = value as? JSON {
- let rejoined = keys.joinWithSeparator(delimiter)
+
+ if keys.count > 1, let subDict = value as? JSON {
+ let rejoined = keys[1..<keys.endIndex].joinWithSeparator(delimiter)
return subDict.valueForKeyPath(rejoined, withDelimiter: delimiter)
}
Hm, if this is done then |
thanks @tholo @stuartervine if you have the time, can you try seeing if your problems are resolved when using branch |
I was having the same problem. |
thanks for that feedback (and @tholo for the solution), i'll do more testing and likely merge it |
now present in |
I think I've run into this issue running func testNestedEncoding() {
var result: [JSON?] = []
result.append(Encoder.encode("stripe.account.legal_entity.last_name")("User"))
result.append(Encoder.encode("stripe.account.legal_entity.dob.year")(2014))
let x = jsonify(result)
print(x)
} Running this in a test with optimization turned on will stop on line 135 of ExtensionDictionary.swift with an EXC_BAD_INSTRUCTION error and print the same I'm getting this error with Xcode 7.3.1. and the newly released Gloss Am I missing something? Thanks! |
hey @sfaxon - thanks for reporting. nope, you're not missing anything; i'll have to do more investigation the temporary solution, of course, would be to not use nested keypaths for the time being |
Reporting the same in my project, both on Changing the Swift Optimization to None (on our custom build configuration called AdHoc) is resolving the problem, but that should be temporary. |
Apologies for the unrelated interjection: @tholo how did you embed that diff? |
Thorsten |
Oh. Used the standard markdown for code, in this case specifying that it was in "diff" format... So, pasted in some code (diff output, in this case), and wrapped it in backtick sections with the opening section saying
This is documented in Creating and highlighting code blocks |
Ahh, thats a really cool feature. Thanks @tholo On Tue, Jun 21, 2016 at 9:42 AM Thorsten Lockert notifications@github.com
|
Reporting in as well and same:
Found it as well in an application distributed via Test Flight. I've disabled optimisations and now it works. |
Here is a quick snippet for those of you who use CocoaPods and wants to disable the code optimization on the pods targets (put it at the end of your post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.name == 'AdHoc'
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] ||= "-Onone"
end
end
end
end We are temporarily using this solution to build adhoc builds for our CI. |
i just released apologies to those who have a lot of nested keypaths! models should be updated before moving to |
Hey @hkellaway - after I read that - the best JSON library written in Swift, that we've been using in both commercial and in-house apps is just making us sad. Could you work on the feature a little bit more? Does the optimization fix does not work for you at this time? |
yes, it's likely possible to turn off optimization for the Release confguration of the library - but that's not what's expected of the configuration. so the choice was turning off the proper optimization level or keep this convenience feature. It's a nice-to-have, not a need-to-have, for any JSON parsing library in my mind - so I chose to stick with the proper settings. I totally get if that's a dealbreaker; I'd recommend you another library that does that if I knew of one. I currently don't have the bandwidth to work on reincorporating it, though may eventually - so I can't give a guarantee. I'm open to others submitting PRs to that effect. another possibility is creating your own fork, reapplying the implementation, and adding what can be done to adjust the optimization level. |
I agree with @hkellaway about keeping the right values for optimisation and dropping the feature.. but must to say as well like many others, that dot notation was a killer feature for me and it is really sad to go back to the messy nested handling |
nested keypaths have been reintroduced as of the latest version, you can thank @ferusinfo for that |
Yayyyyy!!!!! thanks @ferusinfo ... AWESOME! |
With Swift 2.2, I've run into an issue when decoding deep json using the dot syntax. The decoding crashes with the error:
The following test case fails with the above error:
I'm not sure if I'm missing something, but everything seemed ok with Swift 2.1.
The text was updated successfully, but these errors were encountered: