Hello guys, are there any plans in near future make it linux compatible?
Waiting for Linux support Swift
https://swift.org/download/#latest-development-snapshots
Isn't it what are you waiting for, or Im wrong?:)
you can only use terminal to write swift. We need an IDE to write the full project
But you already have one - Xcode. To make code works on linux doesn't mean that it has to be written on linux an linux friendly IDE. Linux can compile project if it was made on Mac, code is code, you know. BTW, what do you mean by saying "we need"? I don't see your contributions in SwiftyJSON :) Maybe developers should answer it.
This is essentially the same issue as mine:
@DarthRamone @hpux735 You could try this pure Swift JSON package TidyJSON that run on all Swift platform.
Or IBM-Swift/SwiftyJSON branch
I've been enjoying https://github.com/postmates/PMJSON so far :)
@shmuelk @ianpartridge It seems that you guys have been maintaining an IBM fork of SwiftyJSON. Would you mind elaborating on the context of the fork and whether it would be worth merging your changes into the main repo? If your fork contains Linux support, as @weakish seems to suggest, it would be really valuable.
Hi, yes the IBM-Swift/SwiftyJSON repo does add support for Linux.
@ianpartridge Interesting. Any other changes that would be worth merging in the main repo? Also, are the changes production-ready or is it just an internal fork that respond to specific IBM needs?
We ported to Swift 3 a while ago, but I guess this repo has that now as well. I think the rest of the work was around compatibility between Darwin NSJSONSerialization and swift-corelibs's version.
Based on the fork mentioned in #748, surprisingly I managed to make all the valid tests cases passed with only tiny bit of modification. Turns out JSONSerialization in swift corelibs really improved. And we don't need the LclJSONSerialization.swift anymore. Here's my change
diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift
index 7544220..a4b197a 100644
--- a/Source/SwiftyJSON.swift
+++ b/Source/SwiftyJSON.swift
@@ -677,7 +677,7 @@ extension JSON: Swift.RawRepresentable {
public var rawValue: Any {
return self.object
}
-
+/*
#if os(Linux)
public func rawData(options opt: JSONSerialization.WritingOptions = JSONSerialization.WritingOptions(rawValue: 0)) throws -> Data {
guard LclJSONSerialization.isValidJSONObject(self.object) else {
@@ -686,7 +686,7 @@ extension JSON: Swift.RawRepresentable {
return try LclJSONSerialization.data(withJSONObject: self.object, options: opt)
}
-#else
+#else*/
public func rawData(options opt: JSONSerialization.WritingOptions = JSONSerialization.WritingOptions(rawValue: 0)) throws -> Data {
guard JSONSerialization.isValidJSONObject(self.object) else {
throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "JSON is invalid"])
@@ -694,7 +694,7 @@ extension JSON: Swift.RawRepresentable {
return try JSONSerialization.data(withJSONObject: self.object, options: opt)
}
-#endif
+//#endif
public func rawString(_ encoding: String.Encoding = .utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String? {
do {
diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift
index 781ba80..08e8bcc 100644
--- a/Tests/SwiftyJSONTests/BaseTests.swift
+++ b/Tests/SwiftyJSONTests/BaseTests.swift
@@ -207,13 +207,13 @@ final class BaseTests: XCTestCase, XCTestCaseProvider {
//https://bugs.swift.org/browse/SR-1464?jql=text%20~%20%22NSNumber%22
//Removed this #if once bug is fix
XCTAssertEqual(JSON(-9999999991999999999999999.88888883433343439438493483483943948341).stringValue,"-9.999999991999999e+24")
- #endif
XCTAssertEqual(JSON(Int(Int.max)).description,"\(Int.max)")
XCTAssertEqual(JSON(NSNumber(value: Int.min)).description,"\(Int.min)")
XCTAssertEqual(JSON(NSNumber(value: UInt.max)).description,"\(UInt.max)")
XCTAssertEqual(JSON(NSNumber(value: UInt64.max)).description,"\(UInt64.max)")
XCTAssertEqual(JSON(NSNumber(value: Int64.max)).description,"\(Int64.max)")
XCTAssertEqual(JSON(NSNumber(value: UInt64.max)).description,"\(UInt64.max)")
+ #endif
XCTAssertEqual(JSON(Double.infinity).description,"inf")
XCTAssertEqual(JSON(-Double.infinity).description,"-inf")
And , bam,
Test Suite 'All tests' passed at 15:32:12.983
Executed 120 tests, with 0 failures (0 unexpected) in 8.99 (8.99) seconds
Basically I just removed LclJSONSerialization.swift and uses JSONSerialization. The NSNumber test cases failed because of known bugs of Swift itself.
I'm on Ubuntu 16.04(amd64) with Swift 3.1 release(March 27, 2017).
CC @wongzigii @zhigang1992 @ianpartridge
Great to hear. Yes, JSONSerialization on Linux is much better in Swift 3.1 - we fixed lots of bugs.
CC @carlbrown from a Kitura POV.
Thanks for following up! I will take a look at this if I get some free time this weekend. 馃憤
CC @ianpartridge @skyline75489 @zhigang1992
I've created #943, any code review would be appreciated 馃檹