Skip to content

Initial implementation of NSNumberFormatter. #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

chrisfsampaio
Copy link
Contributor

  • Added implementation for attributes.
  • Added tests for initial implementation.
  • Updated implementation status documentation.

}

internal var _locale: NSLocale = NSLocale.currentLocale()
/*@NSCopying*/ public var locale: NSLocale! {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another option is to drop the internal var here and use willSet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice!
But I think that on a next step we should do something like this:

    internal var _numberStyle: NSNumberFormatterStyle = .NoStyle
    public var numberStyle: NSNumberFormatterStyle {
        get {
            let rawValue = CFNumberFormatterGetStyle(_cfObject).rawValue
            _numberStyle = NSNumberFormatterStyle(rawValue: UInt(rawValue))!
            return _numberStyle
        }

        set {
            _reset()
            _numberStyle = newValue
        }
    }

And then we would be sure that both our object and the internal CoreFoundation formatter are in sync, which currently isn't happening. We could also take leverage of CoreFoundation number formatter default values.

I really dislike the interval vars too, but I can't think of any other option. 😞
Do you see any other way that allows us to keep both worlds in sync?

@chrisfsampaio chrisfsampaio force-pushed the number-formatter-implementation branch from cf9df8f to dc8e191 Compare December 12, 2015 03:57
@chrisfsampaio
Copy link
Contributor Author

Done, added the missing tests.
In terms of implementation, I guess this is enough for this PR (taking incremental development into account).
Please, let me know if I need to change anything else.

__cfObject = obj
return obj
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things here:

  1. We use the _cfObject method for types which are bridged. I think that the CFNumberFormatter/NSNumberFormatter relationship could instead be 'has-a', as in NSNumberFormatter has a CFNumberFormatterRef. This means we don't have to worry about things like matching up ivar layout. So I would call this internal var something besides _cfObject to avoid confusion.
  2. Whatever we call the internal var backing the internal var, it'd be nice if it was not the same name with just an additional underscore... I feel like it's too easy to mess that up and use it accidentally somewhere in the rest of the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 ef329ed

Regarding (2), what do you think of making it private? If we need access to the internal formatter somewhere else in the lib, one still could use the _cfFormatter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably the case that we want the _cfFormatter to only be used within NSDateFormatter itself; other internal-to-library clients should still use the public API (preferred) or a private swift method (if required for some reason).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I made both of them private then.

@parkera
Copy link
Contributor

parkera commented Dec 12, 2015

I'm going to review some more later but I think this is a great start.

@parkera parkera self-assigned this Dec 12, 2015
@chrisfsampaio
Copy link
Contributor Author

I'm going to review some more later but I think this is a great start.

Nice! 👍

@parkera
Copy link
Contributor

parkera commented Dec 12, 2015

Let's go ahead and rebase this and squash into a single commit for merge. Thanks!

@chrisfsampaio chrisfsampaio force-pushed the number-formatter-implementation branch from ef329ed to b2e832c Compare December 12, 2015 17:19
@chrisfsampaio
Copy link
Contributor Author

Let's go ahead and rebase this and squash into a single commit for merge. Thanks!

👍 Done! Thanks!

I've also reordered the test case to be alphabetically sorted in favor of #111.

@chrisfsampaio chrisfsampaio force-pushed the number-formatter-implementation branch from b2e832c to f2cce4c Compare December 12, 2015 18:02
@chrisfsampaio
Copy link
Contributor Author

I've also updated the status page to reflect the changes made on this PR.

@chrisfsampaio chrisfsampaio force-pushed the number-formatter-implementation branch from f2cce4c to 4272240 Compare December 14, 2015 12:32
- Added implementation for attributes.
- Added unit tests.
- Updated implementation status documentation.
@chrisfsampaio chrisfsampaio force-pushed the number-formatter-implementation branch from 4272240 to 3ac6ee3 Compare December 16, 2015 14:30
@parkera
Copy link
Contributor

parkera commented Dec 16, 2015

Hm, getting 5 test failures, all in the currency paths, but only on Linux.

@parkera
Copy link
Contributor

parkera commented Dec 16, 2015

Ah, the currency stuff is only available on ICU 5.5 or later.

@parkera parkera merged commit 3ac6ee3 into swiftlang:master Dec 16, 2015
@chrisfsampaio chrisfsampaio deleted the number-formatter-implementation branch December 18, 2015 12:56
atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
[swiftpm] Handle symlinks in the workspace path
kateinoigakukun pushed a commit to kateinoigakukun/swift-corelibs-foundation that referenced this pull request Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants