-
-
Save anupamchugh/9b5a61986249c7e594533ebfa9781334 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@EnvironmentObject var iconSettings : IconNames | |
var body: some View { | |
NavigationView { | |
Form { | |
Section{ | |
Picker(selection: $iconSettings.currentIndex, label: Text("Icons")) | |
{ | |
ForEach(0..<iconSettings.iconNames.count) { | |
Text(self.iconSettings.iconNames[$0] ?? "Default") | |
} | |
}.onReceive([self.iconSettings.currentIndex].publisher.first()) { (value) in | |
let index = self.iconSettings.iconNames.firstIndex(of: UIApplication.shared.alternateIconName) ?? 0 | |
if index != value{ | |
UIApplication.shared.setAlternateIconName(self.iconSettings.iconNames[value]){ error in | |
if let error = error { | |
print(error.localizedDescription) | |
} else { | |
print("Success!") | |
} | |
} | |
} | |
} | |
} | |
} .navigationBarTitle("AlternateIcons", displayMode: .inline) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment