Post

Replies

Boosts

Views

Activity

Is there a cleaner way of making an enum with associated value conform to rawRepresentable?
I have this in my code and it works, however if I have a long list it gets tiresome. Is there a better way of having an enum with associated values that also conforms to RawRepresentable? public enum IconColor { case regular case error case warning case success case custom(String) public var value: Color { return loadColor(self.rawValue) } } extension IconColor: RawRepresentable { public var rawValue: String { switch self { case .regular: return "icon_regular" case .error: return "icon_error" case .warning: return "icon_warning" case .success: return "icon_success" case .custom(let value): return value } } public init(rawValue: String) { switch rawValue { case "icon_regular": self = .regular case "icon_error": self = .error case "icon_warning": self = .warning case "icon_success": self = .success default: self = .custom(rawValue) } } }
3
0
715
Jul ’22
How to use dependencies in a Swift Package
I created a new Package with Xcode and incorporated a dependency, however when I try to use it, I get a "No such module" error. How do I use the dependency in the Package sources? In a normal project, I can easily import and use AgileDB. Here's the Package: // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package(     name: "DBCore",     products: [         // Products define the executables and libraries a package produces, and make them visible to other packages.         .library(             name: "DBCore",             targets: ["DBCore"]),     ],     dependencies: [   .package(url: "https://github.com/AaronBratcher/AgileDB", from: "6.4.0")     ],     targets: [         // Targets are the basic building blocks of a package. A target can define a module or a test suite.         // Targets can depend on other targets in this package, and on products in packages this package depends on.         .target(             name: "DBCore",             dependencies: []),         .testTarget(             name: "DBCoreTests",             dependencies: ["DBCore"]),     ] ) Perhaps the AgileDB package as a dependency in the target? I tried copying that and it won't recognize it.
1
0
1k
Apr ’22
Swap rootViewController with animation?
I'm trying to swap out the rootViewController in my appDelegate with an animation and it is just flashing to the new viewController without any animation.-(void)showRootController:(UIViewController *)controller { [UIView transitionWithView:self.window duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ self.window.rootViewController = controller; [self.window makeKeyAndVisible]; } completion:nil]; }How can I do this with an animation? (Testing on an iPhone 5s with iOS 8)
Topic: UI Frameworks SubTopic: UIKit Tags:
3
0
7.4k
Jun ’15