-
Notifications
You must be signed in to change notification settings - Fork 28
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
Simplify enums using .allCases from Swift 4.2 #24
Conversation
Simplified enums by removing as many stored properties as possible and replacing them with computed ones; some renaming to be more Swift like; update to FontAwesome 5.4.2
Looks good but do you think you could do descriptions for all public variables and methods there for autocomplete? If we’re to upgrade a major version then we should improve all of the interface I think |
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.
By making Amazing
conform to RawRepresentable, CaseIterable, CustomStringConvertible where RawValue == String
we can reduce a lot of the code.
All the new computed properties can be moved into (except public static var all
)
extension Amazing {
...
}
but the Image
/ NSAttributedString
inits / methods need to be generalized
e.g.
public convenience init(icon: Amazing, size: CGSize, color: Color = Color.black, backgroundColor: Color = Color.clear) {
}
becomes
public convenience init<AmazingType: Amazing>(icon: AmazingType, size: CGSize, color: Color = Color.black, backgroundColor: Color = Color.clear) {
}
If the interface changes then we up a major version so youguys don’t have to worry about compatibility |
- Moved most computed properties into Amazing - Updated generator and regenerated enums - Fixed a bug where key and description were not return what was expected - Amazing.name now returns the old key (deprecated), Amazing.key returns the old key prepended by the font name and face
OK, I implemented the changes suggested by @divadretlaw and also solved the bug with the keys with a computed property. Being not so experienced with GitHub and creating PRs I did not realize that @divadretlaw already made some code changes that I could have just accepted. So I did the changes myself in my fork which lead to the suggested changes being outdated. Sorry for this, next time. @rafiki270 The interface is compatible but with deprecation notices. I'll leave versioning up to you guys. |
Did some cleanup as the |
Could we please comment on all the public vars and functions if we are raising the new version? |
Happy to merge right after |
@rafiki270 Not fully sure what you mean. Can you give an example of what you have in mind? It looks like autocomplete comments have been removed from Xcode some time ago: |
you can also go before the property or function and do |
@rafiki270 Gotcha. I was missing the |
sorry, |
- Added documentation to all public interfaces - added .detailedKey and .allDetailedKeys to Amazing that contain a unique key with font name, style and icon name; .key now contains only the lowercased icon name - removed CaseIterable from enums as they inherit this from Amazing
@rafiki270 OK, I hope this does what you meant. I also added another computed property to Amazing and removed BTW: The shortcut to document does not work (at least on some) non US keyboards. But I found it in the menu and changed it locally. Very helpful! |
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.
There are still missing comments on the new vars unfortunately
return name | ||
extension Amazing { | ||
|
||
public var detailedKey: String { |
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.
These still missing comments on what they do?
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.
They were already in declaration of the Amazing
protocol and I thought this would be enough. But it looks like the properties appear twice in autocomplete: once with (protocol) and once without (extension) the hint. I'll add them to the extension as well.
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.
Looks like the same thing applies for the deprecation warnings. So I'll add them to the protocol again too.
let name = AwesomeType.keys[index] | ||
return name | ||
|
||
@available(swift, deprecated: 4.2, message: "This will be removed in the future. Please use .allKeys instead") |
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.
You can also do @available(*, unavailable, renamed: "allKeys")
which will offer user the "red dot of fix" in the code ... this is how apple generates their "Fix it!" warnings ...
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.
Yes, but AFAIK this would break downward compatibility as this generates a compiler error instead of a warning. Up to you guys if you want to stay compatible or not.
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 would not worry about compatibility as this will be a major update 2.0.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.
So if we break downward compatibility, then we could/should also remove the deprecated properties from the protocols and mark them only in the extension as renamed, right?
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.
If it’s an extension of that protocol then yes ... also, the content of that extension method or property should be only fatalError
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's a bit problematic as the computed property expects a return type that fatalError
cannot meet. Addind fatalError
before the return
with the correct type generates compiler warnings that the return will never be executed. IMHO there is no need for the fatalError as the compiler will fail on the unavailable
anyway. I'll have another look and submit a proposal.
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.
have you tried? :) ... you need to put it in the get
method, set can be let empty ...
var prop: String {
get { fatalError() }
set { }
}
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.
Nice! I it works when using get/set but not when the properties are declared as read-only computed properties.
Looks good to me ... @ghowen would you like to merge and do a release? It will be |
@rafiki270 Thanks. I've never done that on a public repo and honestly I don't know what else needs to be changed for the release to work properly (like version numbers, pod configs, carthage configs etc.). So maybe someone more experienced can do this one and I'll have a close look at all the changes that were needed for the rollout. Sound OK? |
@ghowen don't forget to add yourself to the list of contributors on README page! :) |
:) Sure, thanks. What do you need to do to update the pod and carthage lib? I saw that the pod is still on 1.3.0 while the lib was already on 1.4.0. |
Also, should you have a read only prop then skip the setter (re fatal error in vars and lets) |
PR in regards to #21
I am not so familiar with creating pull requests so please let me know if this is OK like this. Thanks.