Comments (12)
Thanks!
Opened a pull request here: #7
Let me know if I should have opened it against the branch instead
from swift-jsonpatch.
Hi @chrisschlitt, thanks for reporting these issues regarding linux support. I will look to see the level of effort required for supporting the platform.
from swift-jsonpatch.
Awesome! I'm in desperate need of a package like this for linux, so let me know how I can help in any way!
My hunch is the incomplete porting of Foundation
outside of Apple Platforms. I saw the issue around CFNumberGetType
and thought a potential fix would be conditionally importing the newer FoundationNetworking
framework but sadly that didn't seem to fix it.
from swift-jsonpatch.
I've created a branch called feature/linux-support
. I need to install a linux distro on a vm, as I don't have an environment to test changes.
With regards to CFNumberGetType
, I had a look at NSNumber.swift in the swift corelibs, I'm thinking that property objCType
could be used. Something like the following.
#if os(Linux)
return objCType.pointee == 0x63 // character code for 'c'
#else
return CFNumberGetType(self) == .charType
#endif
from swift-jsonpatch.
I can test things if you need. That does sound like a good solution, when replacing the instance in JSONPatchCodable.swift
, I tried changing the switch to:
#if os(Linux)
switch value.objCType.pointee {
case 0x63:
try encode(value.boolValue)
case 0x64, 0x71, 0x51, 0x4C:
try encode(value.doubleValue)
case 0x66, 0x49:
try encode(value.floatValue)
default:
try encode(value.int64Value)
}
#else
switch CFNumberGetType(value) {
case .charType:
try encode(value.boolValue)
case .cgFloatType, .doubleType, .float64Type:
try encode(value.doubleValue)
case .floatType, .float32Type:
try encode(value.floatValue)
default:
try encode(value.int64Value)
}
#endif
and it will successfully compile, but when trying to generate a patch I get a crash with:
Could not cast value of type 'Swift.String' (0xaaaaca3c58a0) to 'JSONPatch.JSONEquatable' (0xaaaacc327580).
from swift-jsonpatch.
Regarding the fatalError from the cast, I think we'd need a similar extension on String
as we do for NSString
in JSONEquality.swift
.
extension NSString: JSONEquatable {
func isJSONEquals(to element: JSONElement) -> Bool {
guard case let .string(str) = element else {
return false
}
return isEqual(str)
}
}
from swift-jsonpatch.
I added similar extensions for String, Array, and Dictionary and it now builds and runs successfully! At least in my initial testing of generating a patch between two codable objects. This is awesome!
Do you want me to open a PR for this? Or do you want to handle it?
from swift-jsonpatch.
A bit messy, but this is what I tried: https://github.com/chrisschlitt/swift-jsonpatch/blob/feature/linux-support/Sources/JSONPatch/JSONEquality.swift
from swift-jsonpatch.
Do you want me to open a PR for this? Or do you want to handle it?
I think it would be good if you opened a pull request, that way you can get the contributor recognition. I can clean up the code, if required after.
from swift-jsonpatch.
Thanks @chrisschlitt, I updated the pr to target the develop branch, and I've accepted and merged the pr. I'd like to get the unit tests running on linux before making the release, just to check there are no issues.
from swift-jsonpatch.
A good confirmation imo! Thanks for getting to this so quickly and letting me help. No rush on the merge (Iām developing off this branch for now)
from swift-jsonpatch.
Release v1.0.6 published
from swift-jsonpatch.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-jsonpatch.