These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding.
Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding.
Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Topic:
Media Technologies
SubTopic:
Photos & Camera
Tags:
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding.
Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Topic:
Community
SubTopic:
Apple Developers
Word salad. You're not making sense.
Topic:
Community
SubTopic:
Apple Developers
Please don't post duplicates. If you need to update a post, just edit it.
Topic:
App Store Distribution & Marketing
SubTopic:
App Review
Tags:
.onChange has not been deprecated. It has changed. I've given you the current non-deprecated version.
Your first item in the Picker is Text("Select a Handle") and you've set the tag to nil. So, if someone picks the first item then the selectedHandle is going to be nil. That cannot be stored in roundsdata.roundsHandle, because you've said it's 'text' (I'm sure you meant String).
So, just don't update roundsdata.roundsHandle in onChange when it's nil, i.e.:
.onChange(of: selectedHandle) {
if(selectedHandle != nil) {
roundsdata.roundsHandle = selectedHandle
}
}
Next, your players in the ForEach have a player value that you're setting the tag to, so when someone picks something other than the first item (which is nil) it will attempt to set roundsdata.roundsHandle to that value, but your tag is player as PlayerData?.
That means you're trying to set roundsdata.roundsHandle to an Optional(PlayerData). That's why you're getting the error.
You need to set the tag to a String value from the player, not to a PlayerData object.
You have Text(player.playerHandle) so the player.playerHandle is a String. I think that's what you need to set the tag to, i.e.:
Picker("Handle:", selection: $selectedHandle) {
Text("Select a Handle").tag(nil)
ForEach(players, id: \.self) { player in
Text(player.playerHandle)
.tag(player.playerHandle)
}
}
.onChange(of: selectedHandle) {
if(selectedHandle != nil) {
roundsdata.roundsHandle = selectedHandle
}
}
It looks like you don't completely understand how these pickers work because you're over-complicating it. This might help:
Picker("Select something", selection: $thisIsPopulatedWithTheThingSelected) {
// List the things we want in the picker, like days of the week
ForEach(myArrayOfDayStrings, id: \.self) { day in
Text(day) // Shows Monday-Sunday
.tag(day) // For Monday, the tag is Monday. For Tuesday, it's Tuesday etc.
// When someone picks Monday, $thisIsPopulatedWithTheThingSelected becomes Monday. Pick Tuesday and it's Tuesday.
}
}
.onChange(of: thisIsPopulatedWithTheThingSelected) {
print("You picked \(thisIsPopulatedWithTheThingSelected)")
}
I don't want to labour the point, but once you make a post that has code in it you need to look at that post and see whether you've put the backticks in the right place:
Anyway, have you tried adding an .onChange(of:) {} to the DatePicker to print out the value of the variable?
If it's being set correctly, you can then just manually set your value, i.e.:
DatePicker("Date:", selection: $playDate, displayedComponents: [.date])
.onChange(of: playDate) {
roundsdata.roundsDate = playDate
}
The same applies for your Picker, but make sure you add the .onChange(of:) {} to the closing brace for the Picker and not on anything inside it, like the Text and ForEach items.
Is this your code FincancialCoreFrameWork? I ask because "Financial" is spelled incorrectly, and "Framework" is one word not two, so doesn't need the W to be capitalised.
It looks like some error accessing a file? Can you put in some error handling around that?
Also, are you sure this only happens on an M4 Mac? What version of macOS?
Topic:
App & System Services
SubTopic:
General
Tags:
Thanks for your comments, however this is the wrong place for them.
These are the Developer Forums, where developers of third-party apps for Apple's platforms ask each other for hints and tips on coding.
These forums are not where Apple's actual employee developers chat about what they're doing in the platform code.
If you have a suggestion, you should raise it at: https://www.apple.com/feedback/. Thanks.
Topic:
App & System Services
SubTopic:
General
No. This is a terrible user experience.
You should display a modal view that takes over the entire screen, and cannot be dismissed, that explains why the app cannot function.
That's it. You don't need to give the user a button to kill the app. It's unnecessary and a horrible experience.
Topic:
App Store Distribution & Marketing
SubTopic:
App Review
Tags:
It's quite clear that your code formatting didn't work properly when you posted this, so you should've immediately revised it and corrected it. Basically, put three backticks on one line, then all of your code, then another line with just three backticks on it. It's not difficult, and it would help us when reading it.
You've put a bunch of commented code in there. Is it relevant to your issue?
You don't say what line causes the error?
Why does this need to be embedded in a NavigationStack anyway?
Why do you need an HStack around one DatePicker?
At your ForEach(players, id: \.self) { player in line, you have an HStack and a Text with some modifiers (.frame and .tag). Why have you put this in an HStack and then put the same modifiers on the HStack?
Are the five HStacks at the bottom relevant to the issue?
I'm not entirely sure you understand how HStacks work. They place items horizontally. If there's only one item, does it need to be in an HStack?
Please clean up this question and we may be able to help you. In doing so you might actually fix the issue yourself...
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding.
Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Topic:
App & System Services
SubTopic:
General
You just need to apply the right filters. You have this function:
func filteredItems(for category: MenuCategory) -> [MenuItem] {
return sampleMenuItems.filter { $0.category == category }
}
It filters the sampleMenuItems and returns only those items that match the category.
This line: let filteredItems = sampleMenuItems.filter in your ForEach... is pointless and is likely causing your issue.
This:
ForEach(filteredItems) { item in
}
has nothing in it. Also, it's a code smell. You've got a variable called filteredItems AND a function with the same name. Don't do this.
This:
MenuItemRow(item: sampleMenuItems.filter) {
addItemToOrder
}
Again, the sampleMenuItems.filter bit is incorrect.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Hey, App Store Connect Engineer, this is clearly spam. Mark it as such and remove it.
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding.
Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
- Replies
- Boosts
- Views
- Activity
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding.
Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Topic:
Media Technologies
SubTopic:
Photos & Camera
Tags:
- Replies
- Boosts
- Views
- Activity
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding.
Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Topic:
Community
SubTopic:
Apple Developers
- Replies
- Boosts
- Views
- Activity
Word salad. You're not making sense.
Topic:
Community
SubTopic:
Apple Developers
- Replies
- Boosts
- Views
- Activity
Please don't post duplicates. If you need to update a post, just edit it.
Topic:
App Store Distribution & Marketing
SubTopic:
App Review
Tags:
- Replies
- Boosts
- Views
- Activity
.onChange has not been deprecated. It has changed. I've given you the current non-deprecated version.
- Replies
- Boosts
- Views
- Activity
Your first item in the Picker is Text("Select a Handle") and you've set the tag to nil. So, if someone picks the first item then the selectedHandle is going to be nil. That cannot be stored in roundsdata.roundsHandle, because you've said it's 'text' (I'm sure you meant String).
So, just don't update roundsdata.roundsHandle in onChange when it's nil, i.e.:
.onChange(of: selectedHandle) {
if(selectedHandle != nil) {
roundsdata.roundsHandle = selectedHandle
}
}
Next, your players in the ForEach have a player value that you're setting the tag to, so when someone picks something other than the first item (which is nil) it will attempt to set roundsdata.roundsHandle to that value, but your tag is player as PlayerData?.
That means you're trying to set roundsdata.roundsHandle to an Optional(PlayerData). That's why you're getting the error.
You need to set the tag to a String value from the player, not to a PlayerData object.
You have Text(player.playerHandle) so the player.playerHandle is a String. I think that's what you need to set the tag to, i.e.:
Picker("Handle:", selection: $selectedHandle) {
Text("Select a Handle").tag(nil)
ForEach(players, id: \.self) { player in
Text(player.playerHandle)
.tag(player.playerHandle)
}
}
.onChange(of: selectedHandle) {
if(selectedHandle != nil) {
roundsdata.roundsHandle = selectedHandle
}
}
It looks like you don't completely understand how these pickers work because you're over-complicating it. This might help:
Picker("Select something", selection: $thisIsPopulatedWithTheThingSelected) {
// List the things we want in the picker, like days of the week
ForEach(myArrayOfDayStrings, id: \.self) { day in
Text(day) // Shows Monday-Sunday
.tag(day) // For Monday, the tag is Monday. For Tuesday, it's Tuesday etc.
// When someone picks Monday, $thisIsPopulatedWithTheThingSelected becomes Monday. Pick Tuesday and it's Tuesday.
}
}
.onChange(of: thisIsPopulatedWithTheThingSelected) {
print("You picked \(thisIsPopulatedWithTheThingSelected)")
}
- Replies
- Boosts
- Views
- Activity
I don't want to labour the point, but once you make a post that has code in it you need to look at that post and see whether you've put the backticks in the right place:
Anyway, have you tried adding an .onChange(of:) {} to the DatePicker to print out the value of the variable?
If it's being set correctly, you can then just manually set your value, i.e.:
DatePicker("Date:", selection: $playDate, displayedComponents: [.date])
.onChange(of: playDate) {
roundsdata.roundsDate = playDate
}
The same applies for your Picker, but make sure you add the .onChange(of:) {} to the closing brace for the Picker and not on anything inside it, like the Text and ForEach items.
- Replies
- Boosts
- Views
- Activity
Is this your code FincancialCoreFrameWork? I ask because "Financial" is spelled incorrectly, and "Framework" is one word not two, so doesn't need the W to be capitalised.
It looks like some error accessing a file? Can you put in some error handling around that?
Also, are you sure this only happens on an M4 Mac? What version of macOS?
Topic:
App & System Services
SubTopic:
General
Tags:
- Replies
- Boosts
- Views
- Activity
Thanks for your comments, however this is the wrong place for them.
These are the Developer Forums, where developers of third-party apps for Apple's platforms ask each other for hints and tips on coding.
These forums are not where Apple's actual employee developers chat about what they're doing in the platform code.
If you have a suggestion, you should raise it at: https://www.apple.com/feedback/. Thanks.
Topic:
App & System Services
SubTopic:
General
- Replies
- Boosts
- Views
- Activity
No. This is a terrible user experience.
You should display a modal view that takes over the entire screen, and cannot be dismissed, that explains why the app cannot function.
That's it. You don't need to give the user a button to kill the app. It's unnecessary and a horrible experience.
Topic:
App Store Distribution & Marketing
SubTopic:
App Review
Tags:
- Replies
- Boosts
- Views
- Activity
It's quite clear that your code formatting didn't work properly when you posted this, so you should've immediately revised it and corrected it. Basically, put three backticks on one line, then all of your code, then another line with just three backticks on it. It's not difficult, and it would help us when reading it.
You've put a bunch of commented code in there. Is it relevant to your issue?
You don't say what line causes the error?
Why does this need to be embedded in a NavigationStack anyway?
Why do you need an HStack around one DatePicker?
At your ForEach(players, id: \.self) { player in line, you have an HStack and a Text with some modifiers (.frame and .tag). Why have you put this in an HStack and then put the same modifiers on the HStack?
Are the five HStacks at the bottom relevant to the issue?
I'm not entirely sure you understand how HStacks work. They place items horizontally. If there's only one item, does it need to be in an HStack?
Please clean up this question and we may be able to help you. In doing so you might actually fix the issue yourself...
- Replies
- Boosts
- Views
- Activity
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding.
Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Topic:
App & System Services
SubTopic:
General
- Replies
- Boosts
- Views
- Activity
You just need to apply the right filters. You have this function:
func filteredItems(for category: MenuCategory) -> [MenuItem] {
return sampleMenuItems.filter { $0.category == category }
}
It filters the sampleMenuItems and returns only those items that match the category.
This line: let filteredItems = sampleMenuItems.filter in your ForEach... is pointless and is likely causing your issue.
This:
ForEach(filteredItems) { item in
}
has nothing in it. Also, it's a code smell. You've got a variable called filteredItems AND a function with the same name. Don't do this.
This:
MenuItemRow(item: sampleMenuItems.filter) {
addItemToOrder
}
Again, the sampleMenuItems.filter bit is incorrect.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
- Replies
- Boosts
- Views
- Activity
Hey, App Store Connect Engineer, this is clearly spam. Mark it as such and remove it.
- Replies
- Boosts
- Views
- Activity