Posts

Post not yet marked as solved
2 Replies
If you publish a software title that shares same features with an existing one, it can be rejected. Some reviewers check and see if you already have one or more similar titles. You can get a flat rejection. Or they may suggest that you provide new features as add-ons to an existing software title. So you may consider offering in-app purchases. Of course, you can play dumb and submit a new title, which carries a risk of being rejected not now but later on.
Post marked as solved
1 Replies
I've removed the optional part in the framework as follows. And it works. I don't know why the callBack guy can't be optional, though, in the framework. import SwiftUI public struct ColorSelectorView: View { @Binding var selectedColor: Color @State var callBack: ((Color) -> Void) let colors: [Color] = [.blue, .green, .orange, .yellow, .red, .purple] public init(selectedColor: Binding<Color>, callBack: @escaping ((Color) -> Void)) { self._selectedColor = selectedColor self.callBack = callBack } public var body: some View { HStack { ForEach(colors, id: \.self) { color in Image(systemName: selectedColor == color ? "record.circle.fill" : "circle.fill") .foregroundColor(color) .onTapGesture { selectedColor = color callBack(color) } } } } }
Post not yet marked as solved
2 Replies
Employ the color scheme inside the snapView guy. @ViewBuilder func snapView() -> some View { VStack { Text("Text") .background(colorScheme == .light ? .yellow : .brown) Text("Test2") .background(.green) snap snapEx() } }
Post not yet marked as solved
1 Replies
I've made some change the App View as follows. import SwiftUI @main struct LocaleSwitchCrazyMamaApp: App { @StateObject var lanSetting = LanguageSetting() var body: some Scene { WindowGroup { ContentView() .environmentObject(lanSetting) .environment(\.locale, lanSetting.locale) } } } The outcome doesn't change, though.
Post not yet marked as solved
1 Replies
As long as your application already has a functional ability for those who use it with free of charge, I don't see a problem.
Post not yet marked as solved
4 Replies
You can simply use HStack to separate the name text and its corresponding image. import SwiftUI struct ContentView: View { var body: some View { TabView{ FirstView() .tabItem { HStack { Text("Save") .fixedSize() Image(systemName: "lock.fill") } } SecondView() .tabItem { HStack { Text("Things") .fixedSize() Image(systemName: "message.fill") } } } } } struct FirstView: View { var body: some View { Text("First") } } struct SecondView: View { var body: some View { Text("Second") } }
Post not yet marked as solved
2 Replies
It's not working because parent.color in Coordinator is not returned to UIColorPickerViewController. Use a Binding variable in Coordinator to pass the selected color back to UIColorPickerViewController. Besides, why do you use UIColorPickerViewController to access UIColorPickerViewController? SwiftUI has a guy named ColorPicker.
Post not yet marked as solved
2 Replies
I am able to use the contextMenu guy to navigate to another View. Do I miss something? import SwiftUI struct ContentView: View { var body: some View { NavigationStack { FirstView() } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } struct FirstView: View { @State var goToSecond = false var body: some View { VStack { Text("FirstView") .contextMenu { Button("Go to Second View") { goToSecond.toggle() } } } .navigationDestination(isPresented: $goToSecond) { SecondView() } } } struct SecondView: View { var body: some View { VStack { Text("SecondView") } } }
Post not yet marked as solved
1 Replies
I think another approach is use of an ObservableObject class with onReceive(_:perform:) .
Post marked as solved
2 Replies
The following works. Picker(selection: $selectedYear) { ForEach(viewModel.years.indices, id: \.self) { Text("\(viewModel.years[$0])") } } label: { }
Post marked as solved
2 Replies
import SwiftUI struct ProviderCalendarView: View { @StateObject var viewModel = YearViewModel() @State private var selectedYear = 3 var body: some View { VStack { HStack { Picker(selection: $selectedYear) { ForEach(viewModel.years, id: \.self) { year in Text("\(year)") } } label: { } } } } } class YearViewModel: ObservableObject { @Published var years: [Int] = [] init() { createYears() } func createYears() { let now = Date() for i in 0..<4 { years.append(2023 + i) } } } I don't use Range to create an array in this case. Yet, I still get the same compiler guy.
Post marked as solved
1 Replies
Silly me... func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { let fileContent = try JSONEncoder().encode(self.document) return FileWrapper(regularFileWithContents: fileContent) }
Post marked as solved
1 Replies
Replied In Removing More?
I think I've fixed it. import SwiftUI struct ContentView: View { @State var selectedTab = 0 @State var addTapped = false @State var refresh = false @State var people = [ Person(name: "Alice", systemImage: "person.circle.fill"), Person(name: "Jane", systemImage: "person.circle.fill"), Person(name: "Dave", systemImage: "person.circle.fill"), Person(name: "Susan", systemImage: "person.circle.fill"), Person(name: "Robert", systemImage: "person.circle.fill"), Person(name: "Daniel", systemImage: "person.circle.fill") ] var body: some View { VStack(alignment: .leading, spacing: 0) { ScrollView(.horizontal) { HStack(spacing: 20) { ForEach(0..<people.count, id: \.self) { num in VStack { ... } .foregroundColor(selectedTab == num ? Color.blue : Color.gray) .onTapGesture { self.selectedTab = num } } } }.padding(.horizontal, 10) Spacer() .frame(height: 2) Rectangle().fill(.gray) .frame(height: 1) TabView(selection: $selectedTab) { ForEach(0..<people.count, id: \.self) { num in let person = people[num] Text(person.name) .tag(person.id) } } } .tabViewStyle(.page(indexDisplayMode: .never)) // <<<<<<<<<<<<<<<<<<<<< .onAppear { UITabBar.appearance().isHidden = true } } }
Post not yet marked as solved
2 Replies
Thank you for your reply. Yes and no. I've figured out that I can do it by having an additional Date attribute. So I've started with a new Xcode project by having a new Date attribute named createdAt. And code goes as follows. import SwiftUI struct ContentView: View { @Environment(\.managedObjectContext) var managedObject @FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Student.createdAt, ascending: true)]) var students: FetchedResults<Student> var body: some View { VStack { List(students) { student in Text(student.name ?? "") } Button { let firstNames = ... let lastNames = ... if let selectedFirstName = firstNames.randomElement(), let selectedLastName = lastNames.randomElement() { let newStudent = Student(context: managedObject) newStudent.id = UUID() newStudent.name = "\(selectedFirstName) \(selectedLastName)" newStudent.createdAt = Date() // <<<<<<<<<<<<<<<<<<<<<< try? managedObject.save() } } label: { Text("Add") } } } } , which takes care of the sort issue. As for the older project shown above, I wonder if Core Data has a simple mechanism in reordering the records when the entity does not include an additional Date attribute? That was my initial question.