-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Initial implementation of NSNumberFormatter. #132
Conversation
chrisfsampaio
commented
Dec 11, 2015
- Added implementation for attributes.
- Added tests for initial implementation.
- Updated implementation status documentation.
} | ||
|
||
internal var _locale: NSLocale = NSLocale.currentLocale() | ||
/*@NSCopying*/ public var locale: NSLocale! { |
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.
another option is to drop the internal var here and use willSet
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.
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?
cf9df8f
to
dc8e191
Compare
Done, added the missing tests. |
__cfObject = obj | ||
return obj | ||
} | ||
} |
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.
Two things here:
- 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. - 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.
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.
👍 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
.
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.
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).
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.
Makes sense, I made both of them private then.
I'm going to review some more later but I think this is a great start. |
Nice! 👍 |
Let's go ahead and rebase this and squash into a single commit for merge. Thanks! |
ef329ed
to
b2e832c
Compare
👍 Done! Thanks! I've also reordered the test case to be alphabetically sorted in favor of #111. |
b2e832c
to
f2cce4c
Compare
I've also updated the status page to reflect the changes made on this PR. |
f2cce4c
to
4272240
Compare
- Added implementation for attributes. - Added unit tests. - Updated implementation status documentation.
4272240
to
3ac6ee3
Compare
Hm, getting 5 test failures, all in the currency paths, but only on Linux. |
Ah, the currency stuff is only available on ICU 5.5 or later. |
[swiftpm] Handle symlinks in the workspace path
[pull] swiftwasm from main