Skip to content
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

Merged
merged 10 commits into from Oct 30, 2018
Merged

Simplify enums using .allCases from Swift 4.2 #24

merged 10 commits into from Oct 30, 2018

Conversation

ghost
Copy link

@ghost ghost commented Oct 27, 2018

PR in regards to #21

  • Simplified enums by removing as many stored properties as possible and replacing them with computed ones. For this mainly the generator and the Awesome.xxx extensions needed to be changed.
  • Some renaming to be more Swift like but keeping downward compatibility through deprecation warnings. The enums are now capitalized, i.e. FontAwesome.Solid.car instead of FontAwesome.solid.car.
  • updated enums to FontAwesome 5.4.2

I am not so familiar with creating pull requests so please let me know if this is OK like this. Thanks.

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
@ghost ghost mentioned this pull request Oct 27, 2018
@rafiki270
Copy link
Collaborator

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

Copy link
Collaborator

@divadretlaw divadretlaw left a 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) {
}

Generator/Sources/Generator/EnumBuilder.swift Outdated Show resolved Hide resolved
Classes/Extensions/Amazing+Tools.swift Outdated Show resolved Hide resolved
Generator/Sources/Generator/EnumBuilder.swift Outdated Show resolved Hide resolved
@rafiki270
Copy link
Collaborator

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
@ghost
Copy link
Author

ghost commented Oct 28, 2018

OK, I implemented the changes suggested by @divadretlaw and also solved the bug with the keys with a computed property. Amazing cannot implement CustomStringConvertible though as this triggers an endless loop due to reflection in the computed description property. But that's no big deal.

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.

@divadretlaw
Copy link
Collaborator

Did some cleanup as the @available stuff in the protocol did not translate into actual deprecations. Upped the Swift version in all targets and some other general cleanup.

@rafiki270
Copy link
Collaborator

Could we please comment on all the public vars and functions if we are raising the new version?

@rafiki270
Copy link
Collaborator

Happy to merge right after

@ghost
Copy link
Author

ghost commented Oct 28, 2018

@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:
https://stackoverflow.com/questions/41830473/xcode-8-2-1-not-showing-documentation-description-on-autocomplete/43982094#43982094

@rafiki270
Copy link
Collaborator

@rafiki270
Copy link
Collaborator

you can also go before the property or function and do cmd+/

@ghost
Copy link
Author

ghost commented Oct 29, 2018

@rafiki270 Gotcha. I was missing the ///. cmd+/ creates only // on my machine and that did not work as discussed on SO.

@rafiki270
Copy link
Collaborator

sorry, cmd+option+/ ... it will generate even input/output properties on methods, etc ...

- 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
@ghost
Copy link
Author

ghost commented Oct 29, 2018

@rafiki270 OK, I hope this does what you meant. I also added another computed property to Amazing and removed CaseIterable from the enums as they get this through Amazing.

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!

Copy link
Collaborator

@rafiki270 rafiki270 left a 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 {
Copy link
Collaborator

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?

Copy link
Author

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.

Copy link
Author

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")
Copy link
Collaborator

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

Copy link
Author

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.

Copy link
Collaborator

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

Copy link
Author

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?

Copy link
Collaborator

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

Copy link
Author

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.

Copy link
Collaborator

@rafiki270 rafiki270 Oct 30, 2018

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 { }
}

Copy link
Author

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.

@rafiki270
Copy link
Collaborator

Looks good to me ... @ghowen would you like to merge and do a release? It will be 2.0.0 and please describe the changes made in the release notes :) ... good job man!

@ghost
Copy link
Author

ghost commented Oct 30, 2018

@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?

@rafiki270 rafiki270 merged commit c737e81 into LiveUI:master Oct 30, 2018
@rafiki270
Copy link
Collaborator

@ghowen don't forget to add yourself to the list of contributors on README page! :)

@ghost
Copy link
Author

ghost commented Oct 30, 2018

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

@rafiki270
Copy link
Collaborator

Also, should you have a read only prop then skip the setter (re fatal error in vars and lets)

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.

2 participants