- Notifications
You must be signed in to change notification settings - Fork3.4k
Comments
String to Double? conversion fix#910
Conversation
| XCTAssertEqual(json.boolValue, false) | ||
| XCTAssertEqual(json.doubleValue, 0.0) | ||
| XCTAssertEqual(json.numberValue, 0) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| json.string = "swift" | ||
| XCTAssertNil(json.number) | ||
| XCTAssertEqual(json.numberValue, 0) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| XCTAssertEqual(json.numberValue.description, "1000000000000000000000000000.1") | ||
| XCTAssertEqual(json.numberValue, 1000000000000000000000000000.1) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
…Also updated Int code to ensure that "3.14" returns nil (to be more inlines with Int("3.14")), and to return 0 for intValue.| json = "3.14" | ||
| XCTAssertNil(json.int) | ||
| XCTAssertEqual(json.intValue, 0) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| XCTAssertEqual(json.intValue, 9876543210) | ||
| XCTAssertEqual(json.numberValue, 9876543210) | ||
| XCTAssertEqual(json.stringValue, "9876543210") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| XCTAssertEqual(json.int!, 98765421) | ||
| XCTAssertEqual(json.intValue, 98765421) | ||
| XCTAssertEqual(json.numberValue, NSNumber(value: 98765421)) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| XCTAssertEqual(json.floatValue, 9876543210.123456789) | ||
| XCTAssertEqual(json.numberValue, 9876543210.123456789) | ||
| XCTAssertEqual(json.stringValue, "9876543210.123456789") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| XCTAssertEqual(json.float!, -98766.23) | ||
| XCTAssertEqual(json.floatValue, -98766.23) | ||
| XCTAssertEqual(json.numberValue, NSNumber(value: -98766.23)) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| XCTAssertEqual(json.doubleValue, 9876543210.123456789) | ||
| XCTAssertEqual(json.numberValue, 9876543210.123456789) | ||
| XCTAssertEqual(json.stringValue, "9876543210.123456789") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
Source/SwiftyJSON.swift Outdated
| get { | ||
| if let num = self.number as? NSDecimalNumber { | ||
| let returnInt = num.intValue | ||
| if num.isEqual(returnInt){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Opening Brace Spacing Violation: Opening braces should be preceded by a single space and on the same line as the declaration. (opening_brace)
The PR should summarize what was changed and why. Here are some questions to
help you if you're not sure:
What behavior was changed?
Added code for .double to handle strings. Now returns optional or nil.
What code was refactored / updated to support this change?
// MARK: - Number
extension JSON {
//Optional number
public var number: NSNumber?
What issues are related to this PR? Or why was this change introduced?
When trying to convert a string into a .double, it always returned nil
Checklist - While not every PR needs it, new features should consider this list:
Does this have tests?
Yes
Does this have documentation?
No, just adds optional parity to .doubleValue
Does this break the public API (Requires major version bump)?
Don't believe so
Is this a new feature (Requires minor version bump)?
No, this is a bug fix.