Code Monkey home page Code Monkey logo

Comments (12)

chrisschlitt avatar chrisschlitt commented on August 15, 2024 1

Thanks!

Opened a pull request here: #7

Let me know if I should have opened it against the branch instead

from swift-jsonpatch.

raymccrae avatar raymccrae commented on August 15, 2024

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.

chrisschlitt avatar chrisschlitt commented on August 15, 2024

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.

raymccrae avatar raymccrae commented on August 15, 2024

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.

chrisschlitt avatar chrisschlitt commented on August 15, 2024

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.

raymccrae avatar raymccrae commented on August 15, 2024

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.

chrisschlitt avatar chrisschlitt commented on August 15, 2024

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.

chrisschlitt avatar chrisschlitt commented on August 15, 2024

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.

raymccrae avatar raymccrae commented on August 15, 2024

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.

raymccrae avatar raymccrae commented on August 15, 2024

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.

cschlittPHI avatar cschlittPHI commented on August 15, 2024

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.

raymccrae avatar raymccrae commented on August 15, 2024

Release v1.0.6 published

from swift-jsonpatch.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.