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

Fix converting NSNotification.Name to String error #63

Merged
merged 1 commit into from
Feb 4, 2022

Conversation

acosmicflamingo
Copy link
Contributor

This is an attempt to fix the "Cannot convert value of type 'NSNotification.Name' to expected argument type 'String'" issue.

Although appending '.rawValue' resolves the error, it would probably be more elegant if that line is just:
name: UIAccessibility.differentiateWithoutColorDidChangeNotification

Issue information

Right now, I'm getting the following issue when I try and build Capable as a SPM dependency:
"Cannot convert value of type 'NSNotification.Name' to expected argument type 'String'".

Goal

Try and get Capable to compile when used as SPM dependency.

Implementation

Added .rawValue so NSNotification.Name is passed the string value.

Testing

Code compiles after making the change.

This is an attempt to fix the "Cannot convert value of type 'NSNotification.Name' to expected argument type 'String'" issue.

Although appending '.rawValue' resolves the error, it would probably be more elegant if that line is just:
    name: UIAccessibility.differentiateWithoutColorDidChangeNotification
@acosmicflamingo
Copy link
Contributor Author

@chrs1885 Is this something you've encountered at your end? Perhaps this is coming up only on Xcode 13?

@acosmicflamingo
Copy link
Contributor Author

@chrs1885 just a friendly ping :)

@acosmicflamingo
Copy link
Contributor Author

@dehlen @edwellbrook @Deathqon thought I'd send a friendly ping to other potential maintainers just in case.

@chrs1885
Copy link
Owner

chrs1885 commented Feb 4, 2022

@acosmicflamingo thanks for contributing and sry for not reading ti earlier 🍻

@chrs1885 chrs1885 merged commit 2e1adc0 into chrs1885:develop Feb 4, 2022
@acosmicflamingo
Copy link
Contributor Author

@chrs1885 no worries at all! I appreciate that you even replied, but am happier to have this merged in develop now 😄 it was something I had to manually do every time I obliterated DerivedData and Xcode would fetch sources from upstream via SPM 😜

@chrs1885
Copy link
Owner

chrs1885 commented Feb 4, 2022

@acosmicflamingo What are you using the library for? Any feature requests? 😀

@acosmicflamingo acosmicflamingo deleted the patch-1 branch February 4, 2022 23:18
@acosmicflamingo
Copy link
Contributor Author

acosmicflamingo commented Feb 4, 2022

@chrs1885 I'm creating my own "CosmicFlamingoKit" to make my own apps and I have a "CFKAccessibilityLibrary" that uses your library as the backend. Since you asked however.......... :D

It would be cool to add a few cases to CapableFeature enum (accessibilitySize, highContrast, and darkMode), although there might be a reason it is currently not supported (or perhaps I just didn't read the documentation that well!). I'm doing this to get around it:

   /// Check whether an accessibility category is enabled using Capable.CapableFeature enum
   /// - Parameter feature: type of feature from Capable framework
   /// - Returns: true if feature is enabled; false if otherwise
   public static func isEnabled(_ feature: CapableFeature) -> Bool {
       return shared.isFeatureEnabled(feature: feature)
   }

   /// Check whether an accessibility category is enabled using CFA11y.Feature enum
   /// - Parameter feature: type of feature from CFAccessibility framework
   /// - Returns: true if feature is enabled; false if otherwise
   public static func isEnabled(_ feature: CFA11yFeature) -> Bool {
       let traits = UIView().traitCollection
       switch feature {
           case .accessibleSize:
               return traits.preferredContentSizeCategory.isAccessibilityCategory
           case .highContrast:
               return traits.accessibilityContrast == .high
           case .darkMode:
               return traits.userInterfaceStyle == .dark
       }
   }

As you can see, I have a CFA11y class where I can do something like call CFA11y.isEnabled(.reduceMotion). However, I didn't see accessibilitySize, highContrast, or darkMode in CapableFeature enum, which is why I had to write my own enum comprising these cases in CFA11yFeature and a function that uses this type as the feature parameter. That way, I can still use the 'isEnabled' function and not worry about what's going on in the backend.

If this seems like an endeavor worth pursuing, I could try and implement this on Capable framework's side and create a PR instead of just telling you "This is what I want. Good luck" LOL what are your thoughts?

@chrs1885
Copy link
Owner

Hi @acosmicflamingo, sorry for not being more responsive :) First and foremost, thanks for the MR, I just released 2.0.1 🥳

Feel free to add those features as part of a new merge request. 🍻

@acosmicflamingo
Copy link
Contributor Author

@chrs1885 thank you; I'm so glad to hear! :D I will certainly do so!

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