Post

Replies

Boosts

Views

Activity

Reply to How deploy Mac app on local computer
You can archive the app and have a copy that stored locally on your computer. In the menu bar, go to Product > Archive In the Archives window that opens, select the version you want and click Distribute App Select Copy App as the distribution method Choose a name and location then click Export Open the folder that you just created and double-click the app file inside to run it
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to How to sort birthdays in swiftUI so that next birthday from today is on top of the list?
I have just created a playground to test this code out. It seems to work properly for the dates I have provided. See what you think and whether it works in your project. let calendar = Calendar.current // Manual creation of dates so you can see what the values for each are let components = [     DateComponents(year: 2004, month: 3, day: 26),     DateComponents(year: 1973, month: 7, day: 4),     DateComponents(year: 1992, month: 4, day: 1),     DateComponents(year: 2012, month: 12, day: 23),     DateComponents(year: 1988, month: 9, day: 16) ] let birthdays = components.compactMap(calendar.date) // You would only need this bit in your project let nextBirthdays = birthdays.compactMap {     let components = calendar.dateComponents([.day, .month], from: $0)     return calendar.nextDate(after: .now, matching: components, matchingPolicy: .nextTime) }.sorted(by: <) let nextBirthday = nextBirthdays.first print(nextBirthday) // Optional(2022-12-23 00:00:00 +0000) This part is what you would put in your project: // Wrap up next birthday calculation inside a function func nextBirthday(for birthday: Date) -> Date { let calendar = Calendar.current let components = calendar.dateComponents([.day, .month], from: birthday)     return calendar.nextDate(after: .now, matching: components, matchingPolicy: .nextTime) ?? .distantFuture } // Sorted friends by next birthday first friends.sorted { nextBirthday(for: $0.bday) < nextBirthday(for: $1.bday) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to navigate to another view Swiftui
You can use a special type of button that is specifically for navigation called NavigationLink. Use it like this: NavigationLink { // destination view to navigation to DetailView() } label: { Image(systemName: "list.dash")      .foregroundColor(.gray) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to Display fetched data in SwiftUI
You're kind of mixing up two approaches here: completion handlers and return values, like seen with async/await. Since your data fetch is using a completion handler, you can follow this route and add a completion closure parameter to the getData function which can then be called when you get the data. Here's an example of what this would look like: private func getData(from url: String, completion: @escaping (Response) -> Void) {     let task = URLSession.shared.dataTask(with: URL(string: url)!) { data, response, error in         ... completion(json)     }     task.resume() } // in SwiftUI View .onAppear { getData(from: url) { results = $0 } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to No replacement for MKMaptype globe view in iOS16?
There are three subclasses of MKMapConfiguration: MKStandardMapConfiguration MKHybridMapConfiguration MKImageryMapConfiguration Here are some example conversions from MKMapType to MKMapConfiguration: // MKMapType.standard MKStandardMapConfiguration(elevationStyle: .flat) // MKMapType.satellite MKImageryMapConfiguration(elevationStyle: .flat) // MKMapType.hybrid MKHybridMapConfiguration(elevationStyle: .flat) // MKMapType.satelliteFlyover MKImageryMapConfiguration(elevationStyle: .realistic) // MKMapType.hybridFlyover MKHybridMapConfiguration(elevationStyle: .realistic) // MKMapType.mutedStandard MKStandardMapConfiguration(emphasisStyle: .muted)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to Xcode Missing checkbox "Support Multiple Windows"
Click on the little arrow next to "Supports multiple windows", or go to the "Info" tab, and you will see a small property list table Expand the row that says "Application Scene Manifest" Inside you will see the key "Enable Multiple Windows" Set the value for this to YES (the default) If any of these keys are not there, you will have to add them yourself. I don't know if the checkbox was removed intentionally or not, but it does seem a little strange.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’22
Reply to Constraint for views in SwiftUI
You can use the Spacer() view which will take up all available space. It will also share this space equally when there are multiple. VStack { ViewA() Spacer() // push ViewA to the top ViewB() // takes up the available space Spacer() // push ViewC to the bottom ViewC() } You could also give ViewB a fixed height but I guess you don't want to do that.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to NavigationSplitView No Toggle Button
Why is there no toggle button above? What do you mean by "toggle button"? Do you mean the button that hides and shows the sidebar? This is only present when the horizontalSizeClass is .regular. On an iPhone in portrait mode, it won't appear. ‎  And why is the menu always showing? What "menu" are you talking about? ‎ I cant see the detiail view anymore If you want to see the detail view, you need to select an item from the list. As I said before, the two-column layout with the sidebar toggle button is only present when the horizontalSizeClass is .regular. In your screenshot (an iPhone in portrait mode) the NavigationSplitView collapses down to a single column layout and acts more like a NavigationStack.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to how i make List with storyboard?
If I'm understanding what you're saying, you need to set the UITableView style to .insetGrouped.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to SwiftUI Picker doesn't use NavigationView
I believe in iOS 16.1 this feature was put back in SwiftUI, but in the form of a new picker style (since the default is .menu). It's called .navigationLink and is available from iOS 16.0.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to SwiftUI Image has no member 'resizable'
It seems like Image is being interpreted as a UIImage instead of a SwiftUI.Image. Maybe you have something like this in your code: typealias Image = UIImage
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to How deploy Mac app on local computer
You can archive the app and have a copy that stored locally on your computer. In the menu bar, go to Product > Archive In the Archives window that opens, select the version you want and click Distribute App Select Copy App as the distribution method Choose a name and location then click Export Open the folder that you just created and double-click the app file inside to run it
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to How to sort birthdays in swiftUI so that next birthday from today is on top of the list?
I have just created a playground to test this code out. It seems to work properly for the dates I have provided. See what you think and whether it works in your project. let calendar = Calendar.current // Manual creation of dates so you can see what the values for each are let components = [     DateComponents(year: 2004, month: 3, day: 26),     DateComponents(year: 1973, month: 7, day: 4),     DateComponents(year: 1992, month: 4, day: 1),     DateComponents(year: 2012, month: 12, day: 23),     DateComponents(year: 1988, month: 9, day: 16) ] let birthdays = components.compactMap(calendar.date) // You would only need this bit in your project let nextBirthdays = birthdays.compactMap {     let components = calendar.dateComponents([.day, .month], from: $0)     return calendar.nextDate(after: .now, matching: components, matchingPolicy: .nextTime) }.sorted(by: <) let nextBirthday = nextBirthdays.first print(nextBirthday) // Optional(2022-12-23 00:00:00 +0000) This part is what you would put in your project: // Wrap up next birthday calculation inside a function func nextBirthday(for birthday: Date) -> Date { let calendar = Calendar.current let components = calendar.dateComponents([.day, .month], from: birthday)     return calendar.nextDate(after: .now, matching: components, matchingPolicy: .nextTime) ?? .distantFuture } // Sorted friends by next birthday first friends.sorted { nextBirthday(for: $0.bday) < nextBirthday(for: $1.bday) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to navigate to another view Swiftui
You can use a special type of button that is specifically for navigation called NavigationLink. Use it like this: NavigationLink { // destination view to navigation to DetailView() } label: { Image(systemName: "list.dash")      .foregroundColor(.gray) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to How to dismiss a Sheet and open a NavigationLink in a new View?
You have already posted this question here to which I have provided a possible solution.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Display fetched data in SwiftUI
You're kind of mixing up two approaches here: completion handlers and return values, like seen with async/await. Since your data fetch is using a completion handler, you can follow this route and add a completion closure parameter to the getData function which can then be called when you get the data. Here's an example of what this would look like: private func getData(from url: String, completion: @escaping (Response) -> Void) {     let task = URLSession.shared.dataTask(with: URL(string: url)!) { data, response, error in         ... completion(json)     }     task.resume() } // in SwiftUI View .onAppear { getData(from: url) { results = $0 } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to No replacement for MKMaptype globe view in iOS16?
There are three subclasses of MKMapConfiguration: MKStandardMapConfiguration MKHybridMapConfiguration MKImageryMapConfiguration Here are some example conversions from MKMapType to MKMapConfiguration: // MKMapType.standard MKStandardMapConfiguration(elevationStyle: .flat) // MKMapType.satellite MKImageryMapConfiguration(elevationStyle: .flat) // MKMapType.hybrid MKHybridMapConfiguration(elevationStyle: .flat) // MKMapType.satelliteFlyover MKImageryMapConfiguration(elevationStyle: .realistic) // MKMapType.hybridFlyover MKHybridMapConfiguration(elevationStyle: .realistic) // MKMapType.mutedStandard MKStandardMapConfiguration(emphasisStyle: .muted)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to SwiftUI List on maCOS: highlighting content in the selected row?
There is a modifier called listItemTint(_:) that seems like it should do what you are asking for. It's worth checking out, but I believe the behaviour changed in iOS 15 for some reason, intentionally or not.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Xcode Missing checkbox "Support Multiple Windows"
Click on the little arrow next to "Supports multiple windows", or go to the "Info" tab, and you will see a small property list table Expand the row that says "Application Scene Manifest" Inside you will see the key "Enable Multiple Windows" Set the value for this to YES (the default) If any of these keys are not there, you will have to add them yourself. I don't know if the checkbox was removed intentionally or not, but it does seem a little strange.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Constraint for views in SwiftUI
You can use the Spacer() view which will take up all available space. It will also share this space equally when there are multiple. VStack { ViewA() Spacer() // push ViewA to the top ViewB() // takes up the available space Spacer() // push ViewC to the bottom ViewC() } You could also give ViewB a fixed height but I guess you don't want to do that.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Safely converting optional state to non optional binding
Could you not just do this: // unwrap variable normally if let nonOptional = optional_ { // create new binding using unwrapped value let binding = Binding { nonOptional } set: { optional_ = $0 } ChildView(nonOptional: binding) ... }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to NavigationSplitView No Toggle Button
Why is there no toggle button above? What do you mean by "toggle button"? Do you mean the button that hides and shows the sidebar? This is only present when the horizontalSizeClass is .regular. On an iPhone in portrait mode, it won't appear. ‎  And why is the menu always showing? What "menu" are you talking about? ‎ I cant see the detiail view anymore If you want to see the detail view, you need to select an item from the list. As I said before, the two-column layout with the sidebar toggle button is only present when the horizontalSizeClass is .regular. In your screenshot (an iPhone in portrait mode) the NavigationSplitView collapses down to a single column layout and acts more like a NavigationStack.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Upgrade Swift Playgrounds App to iOS 16
Could you not just create a new empty app and then copy over all of the files and settings?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22