Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

String to Double? conversion fix#910

Open
Causaelity wants to merge 4 commits intoSwiftyJSON:masterfrom
Causaelity:doubleStringFix
Open

String to Double? conversion fix#910
Causaelity wants to merge 4 commits intoSwiftyJSON:masterfrom
Causaelity:doubleStringFix

Conversation

@Causaelity
Copy link

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.

kevinvanmierlo and mortenholmgaard reacted with thumbs up emoji
XCTAssertEqual(json.boolValue, false)
XCTAssertEqual(json.doubleValue, 0.0)
XCTAssertEqual(json.numberValue, 0)

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)

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)

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)

@CausaelityCausaelity changed the titleDouble string fixString to Double? conversion fixNov 11, 2017
…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)

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")

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))

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")

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))

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")

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)

get {
if let num = self.number as? NSDecimalNumber {
let returnInt = num.intValue
if num.isEqual(returnInt){

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)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@houndci-bothoundci-bothoundci-bot left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@Causaelity@houndci-bot

[8]ページ先頭

©2009-2026 Movatter.jp