Search results for

“column”

2,089 results found

Post

Replies

Boosts

Views

Activity

Reply to Swift performance - efficient calculation of boolean logical operations
I have a follow up question. I have not implemented the BNNS approach proposed above and it works. However, the calculation speed is still about 3 times as high when I use a similar approach in Python - without any particular special packages or approaches on Python side. I was hoping that Swift would generally be faster so wanted to get your view on whether maybe my approach is generally flawed and her any potential alternatives. I would love to continue with coding in Swift on the project but with runtime being 300% it is just too compelling to rather use Python. Let me explain what I am doing: I create a lot of (random) binary trees which contain arithmetic or logic operations in all non-leaf nodes and numeric arrays (all of the same length) on leaf nodes which are taken from return_data. I.e. my trees are representing (simple) mathematic formulas. I have tens of thousands such trees and need to efficiently evaluate them. I currently do this via a recursive function evaluate_signal. As said above, the same
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’22
Scroll conflict when there is ScrollView inside a ScrollView in SwiftUI
I'm trying to reproduce in a way the finder column view, but I'm facing an issue. A scroll conflict occurs when I put a ScrollView or a List inside another ScrollView. The horizontal scroll is lagging when the cursor is over the nested ScrollView. Here is my simplified code: struct SplitView: View { var body: some View { ScrollView(.horizontal, showsIndicators: false){ HSplitView{ ScrollView(showsIndicators: false) { VStack(alignment: .leading) { ForEach(0..<100) { Text(Row ($0)) } }.frame(minWidth: 200, alignment: .leading) } ScrollView { VStack(alignment: .leading) { ForEach(0..<100) { Text(Row ($0)) } }.frame(minWidth: 200, alignment: .leading) } ScrollView { VStack(alignment: .leading) { ForEach(0..<100) { Text(Row ($0)) } }.frame(minWidth: 200, alignment: .leading) } } } } } I have the same issue with nested List. Do you have any idea how I can prevent that? Or any workaround?
2
0
945
Nov ’22
Reply to Scroll conflict when there is ScrollView inside a ScrollView in SwiftUI
Yes sorry, I'm using MacOS 13.0.1 - Xcode 14.1 I'm basically trying to mimic the finder column view. So, to have multiple Lists that are horizontally aligned. If there is too many List for the window size, then I can scroll horizontally. When I use VStack instead of List/ScrollView, it works perfectly. When I use List/ScrollView, if the cursor is over the nested List/ScrollView, the horizontal scroll lags. But if the cursor is next to the nested List/ScrollView, the horizontal scroll works fine. Here is a video that shows the issue. https://www.youtube.com/watch?v=_UdlNZQH6Pg
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to swipeActions on macOS?
Even with two columns and a Label. It does not work for me. I am using Xcode 14 and Monterey var body: some View { VStack { List(podcast.episodes!) { episode in EpisodeView(podcast: podcast, episode: episode) .swipeActions(edge: .trailing) { Button (action: { self.deleteEpisode(episode) }) { Label(Delete, systemImage: trash) } .tint(.red) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to SwiftUI MacOS TableColumn compiler can't type-check expression in reasonable time.
I found this problem as well. My solution is not very elegant, I'm afriad. I had to be very specific about the types. I moved the columns into their own @TableColumnBuilder with all the generics specified: @TableColumnBuilder private var columns: TupleTableColumnContent< Weather.State.Row, Never, ( TableColumn, TableColumn, TableColumn, TableColumn, TableColumn, TableColumn ) > { TableColumn(Local Date/Time, value: .dateTime) TableColumn(Temperature, value: .temp) TableColumn(Apparent Temperature, value: .apparentTemp) TableColumn(Dew Point, value: .dewPoint) TableColumn(Humidity, value: .humidity) TableColumn(Rain, value: .rain) } Though this is a lot of ugly specificity, it's the type inference that slowing Swift down here. I was lucky because I don't need a sort comparator (hence the Never above) and all my labels and views are simply Texts. There may be a way to clean this up further with buildPartialBlock
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Error Domain=NSCocoaErrorDomain Code=3840 AND
Hello, I have a problem when I launch the application I have this error displayed in the log of the swift: Error Domain=NSCocoaErrorDomain Code=3840 JSON text did not have any content around line 2, column 0. UserInfo={NSDebugDescription=JSON text did not have any content around line 2, column 0., NSJSONSerializationErrorIndex=1} here is the php : set_charset(utf8mb4); // Check connection if (mysqli_connect_errno()) { echo Failed to connect to MySQL: . mysqli_connect_error(); } // This SQL statement selects ALL from the table 'Locations' $sql = SELECT `id`,`nom`,`prenom`,`tel`,`email`,`mdp`,`adr`,`cp`,`ville` FROM clients; // Check if there are results if ($result = mysqli_query($con, $sql)) { // If so, then create a results array and a temporary one // to hold the data $resultArray = array(); $tempArray = array(); // Loop through each row in the result set while($row = $result->fetch_object()) { // Add each row into our results array $tempArray = $row; array_push($resultArray, $tempArra
5
0
1.8k
Nov ’22
Reply to Error Domain=NSCocoaErrorDomain Code=3840 AND
my bad i forgot my code : import Foundation import UIKit protocol HomeModelDelegate { func itemsDowloaded(client:[Client] ) } class HomeModel : NSObject { var delegate:HomeModelDelegate? func getItems(){ //Hit the conn url let serviceURL = http://myFTPSERVER/service.php //Download the JSON Data let url = URL(string: serviceURL) if let url = url { // Create a URL Session let session = URLSession(configuration: .default) let task = session.dataTask(with: url) { (data, url, error) in if let data = data { //Succed print(data) //call the parseJson self.parseJson(data) }else{ } } // Start the task task.resume() } //notify the view controller and pass the data back } func parseJson(_ data:Data){ var clientArray = [Client]() do { //Parse the data into Client structs let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as! [Any] print(jsonArray) //loop through each result in the json array for jsonResult in jsonArray { //Cast json result as a dictionary let jsonDict = jsonResult as! [String:String
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’22
How to add an IBAction to a macOS tableView Cell
I have a macOS tableview I have a textfield as a column along with an IBAction code to capture the data from this field. I wanted to add continuous spell check for this column . So, I decided to change the column from a TextField to a ScrollView to take advantage of the continuous spell check. Using Xcode 14 I changed the Cell to a custom Cell. The custom cell has a scrollview object as the object because I want to take advantage of the built in continuous spell checking instead of using a textfield. All is well with this implementation until I tried to add a IBAction code for when I enter text in the scrollview/textView field. There does not seem to be a way to capture the text? Am I trying to do something that can't be done or is there a way to add continuous spell check to a textField?
4
0
1.4k
Nov ’22
Reply to How to add an IBAction to a macOS tableView Cell
To get access from the VC, you should, in the VC: create an IBOutlet for the tableView (not its container ScrollView) get a reference to the cell, with something like (adapt row and column values) guard let cell = tableView.view(atColumn: 0, row: 0, makeIfNecessary: true) as? CustomTableCell else { return } then use the cell to access any component you need: let text = cell.testTextView.textStorage?.string
Topic: UI Frameworks SubTopic: AppKit Tags:
Nov ’22
Mac Catalyst: UINavigationController incorrectly blocks -setViewControllers:animated: call on UINavigationController when a transition/presentation is occurring on a different view controller.
I have a triple UISplitViewController. A UINavigationController is in the secondary column. When the selection changes in the supplementary column I call -setViewControllers:animated: and pass the navigation controller the new vc. I noticed sometimes the navigation view controller isn't updating and this logs out: setViewControllers:animated: called on while an existing transition or presentation is occurring; the navigation stack will not be updated. So this happens when the Split View controller itself is presenting another view controller modally (say a view controller with a UIActivityIndicatorView in it to show loading progress). But there is no transition/presentation occurring on the UINavigationController contained in the secondary view controller column itself. The presentation occurring on the UISplitViewController is completely separate and unrelated to the UINavigationController's navigation stack that's in the secondary column and therefore I should not be prev
1
0
783
Nov ’22
NavigationSplitView No Toggle Button
I went back to square one since the NavigationLink isActive is deprecated, this is when I found out about NavigationSplitView which removes the hassle of creating a 2 column app. However, I can never figure out why the toggle button does not show. I copied this sample code (already tried 2 tutorials, copy pasted them but still no toggle button) Anyone know why? import SwiftUI enum DemoScreen: String, Codable { case first, second, third var title: String { rawValue.capitalized } } struct ContentView: View { @State private var selection: DemoScreen? = .first var body: some View { NavigationSplitView { sidebarContent } detail: { detailContent } } } extension ContentView { var sidebarContent: some View { List { link(to: .first) link(to: .second) link(to: .third) } } func link(to page: DemoScreen) -> some View { NavigationLink(value: page) { Text(page.title) } } } extension ContentView { @ViewBuilder var detailContent: some View { if let selection = selection { detailContent(for: selection) .buttonStyl
1
0
932
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
Mac Catalyst: UISplitViewControllerColumnSecondary doesn't get key focus when the Tab Key is Pressed in a Triple UISplitViewController.
My UISplitViewController is configured like this: A list (collection view) is used in the primary view controller (sidebar style). When a selection is made in the primary view controller a table view displays data in the supplementary column. When a selection is made in the supplementary view controller, a view controller with scrollable content is shown in the secondary view controller. This is like the Mail app on Mac. So when I run the app I hit the tab key once and the list (collection view) in the primary column gets focus. I can navigate the list with the keyboard. This works as expected. So now with a selection in the list, a table view is showing in the supplementary column. I hit the tab key again and the table view gets focus. This works as expected as I can navigate the table view from the keyboard with the arrow keys. Now with a selection made in the table view, the scrollable view controller is showing in the secondary view controller column. I hit the tab key
3
0
917
Nov ’22
How to fix these errors?
Hello there! I want to create a cards game, and I'm creating it following the Stanford University's tutorial. I followed the video step by step but there is a warning that In the video doesn't appear. Can someone help me to fix it? Here's the link of the video: [https://www.youtube.com/watch?v=oWZOFSYS5GE&t=671s) This is my code: import SwiftUI struct ContentView: View { var emojis =[🚲,🚂,🚁,🚜,🚕,🏎,🚑,🚓,🚒,🚁,🚀,⛵️,🛸,🛶,🚌,🛺,🚇,🚠,🦽,🚗,🚚,🛴,🛵,🚅] @State var emojiCount: Int = 4 var body: some View { ScrollView { LazyVGrid(columns: [GridItem(), GridItem(), GridItem()]) { HStack { ForEach(emojis[0.. 1 { // here's the first error which says Cannot find 'emojiCount' in scope' emojiCount -= 1 // here's the same error which says Cannot find 'emojiCount' in scope' } } label: { Image(systemName: minus.circle) } } var add: some View { Button { if emojiCount < emojis.count { // here's the same error which says Cannot find 'emojiCount' in scope' emojiCount += 1 // here's the same error which says
4
0
629
Oct ’22
Reply to How to fix these errors?
Do you mean those warnings ? if emojiCount > 1 { // here's the first error which says Cannot find 'emojiCount' in scope' emojiCount -= 1 // here's the same error which says Cannot find 'emojiCount' in scope' } You're new to the forum, so welcome. And get a few advices: You'd better expose error messages clearly and not let others search for them in code… when you post code to avoid leaving 20 blank lines… Use Paste and Match Style and then code formatter tool. That will make your code easier to read. I noted several errors: var emojis = [🚲,🚂,🚁,🚜,🚕,🏎,🚑,🚓,🚒,🚁,🚀,⛵️,🛸,🛶,🚌,🛺,🚇,🚠,🦽,🚗,🚚,🛴,🛵,🚅] There need a space after =before [ var remove: some View { is defined out of struct ContentView: View { Hence, @State var emojiCount is not visible out of its scope (the struct). Probably, you have a misplaced closing parenthesis. This should be correct: import SwiftUI struct ContentView: View { var emojis = [🚲,🚂,🚁,🚜,🚕,🏎,🚑,🚓,🚒,🚁,🚀,⛵️,🛸,🛶,🚌,🛺,🚇,🚠,🦽,🚗,🚚,🛴,🛵,🚅] @State var emojiCoun
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’22
Reply to Swift performance - efficient calculation of boolean logical operations
I have a follow up question. I have not implemented the BNNS approach proposed above and it works. However, the calculation speed is still about 3 times as high when I use a similar approach in Python - without any particular special packages or approaches on Python side. I was hoping that Swift would generally be faster so wanted to get your view on whether maybe my approach is generally flawed and her any potential alternatives. I would love to continue with coding in Swift on the project but with runtime being 300% it is just too compelling to rather use Python. Let me explain what I am doing: I create a lot of (random) binary trees which contain arithmetic or logic operations in all non-leaf nodes and numeric arrays (all of the same length) on leaf nodes which are taken from return_data. I.e. my trees are representing (simple) mathematic formulas. I have tens of thousands such trees and need to efficiently evaluate them. I currently do this via a recursive function evaluate_signal. As said above, the same
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’22
Scroll conflict when there is ScrollView inside a ScrollView in SwiftUI
I'm trying to reproduce in a way the finder column view, but I'm facing an issue. A scroll conflict occurs when I put a ScrollView or a List inside another ScrollView. The horizontal scroll is lagging when the cursor is over the nested ScrollView. Here is my simplified code: struct SplitView: View { var body: some View { ScrollView(.horizontal, showsIndicators: false){ HSplitView{ ScrollView(showsIndicators: false) { VStack(alignment: .leading) { ForEach(0..<100) { Text(Row ($0)) } }.frame(minWidth: 200, alignment: .leading) } ScrollView { VStack(alignment: .leading) { ForEach(0..<100) { Text(Row ($0)) } }.frame(minWidth: 200, alignment: .leading) } ScrollView { VStack(alignment: .leading) { ForEach(0..<100) { Text(Row ($0)) } }.frame(minWidth: 200, alignment: .leading) } } } } } I have the same issue with nested List. Do you have any idea how I can prevent that? Or any workaround?
Replies
2
Boosts
0
Views
945
Activity
Nov ’22
Reply to Scroll conflict when there is ScrollView inside a ScrollView in SwiftUI
Yes sorry, I'm using MacOS 13.0.1 - Xcode 14.1 I'm basically trying to mimic the finder column view. So, to have multiple Lists that are horizontally aligned. If there is too many List for the window size, then I can scroll horizontally. When I use VStack instead of List/ScrollView, it works perfectly. When I use List/ScrollView, if the cursor is over the nested List/ScrollView, the horizontal scroll lags. But if the cursor is next to the nested List/ScrollView, the horizontal scroll works fine. Here is a video that shows the issue. https://www.youtube.com/watch?v=_UdlNZQH6Pg
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to swipeActions on macOS?
Even with two columns and a Label. It does not work for me. I am using Xcode 14 and Monterey var body: some View { VStack { List(podcast.episodes!) { episode in EpisodeView(podcast: podcast, episode: episode) .swipeActions(edge: .trailing) { Button (action: { self.deleteEpisode(episode) }) { Label(Delete, systemImage: trash) } .tint(.red) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to SwiftUI MacOS TableColumn compiler can't type-check expression in reasonable time.
I found this problem as well. My solution is not very elegant, I'm afriad. I had to be very specific about the types. I moved the columns into their own @TableColumnBuilder with all the generics specified: @TableColumnBuilder private var columns: TupleTableColumnContent< Weather.State.Row, Never, ( TableColumn, TableColumn, TableColumn, TableColumn, TableColumn, TableColumn ) > { TableColumn(Local Date/Time, value: .dateTime) TableColumn(Temperature, value: .temp) TableColumn(Apparent Temperature, value: .apparentTemp) TableColumn(Dew Point, value: .dewPoint) TableColumn(Humidity, value: .humidity) TableColumn(Rain, value: .rain) } Though this is a lot of ugly specificity, it's the type inference that slowing Swift down here. I was lucky because I don't need a sort comparator (hence the Never above) and all my labels and views are simply Texts. There may be a way to clean this up further with buildPartialBlock
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Error Domain=NSCocoaErrorDomain Code=3840 AND
Hello, I have a problem when I launch the application I have this error displayed in the log of the swift: Error Domain=NSCocoaErrorDomain Code=3840 JSON text did not have any content around line 2, column 0. UserInfo={NSDebugDescription=JSON text did not have any content around line 2, column 0., NSJSONSerializationErrorIndex=1} here is the php : set_charset(utf8mb4); // Check connection if (mysqli_connect_errno()) { echo Failed to connect to MySQL: . mysqli_connect_error(); } // This SQL statement selects ALL from the table 'Locations' $sql = SELECT `id`,`nom`,`prenom`,`tel`,`email`,`mdp`,`adr`,`cp`,`ville` FROM clients; // Check if there are results if ($result = mysqli_query($con, $sql)) { // If so, then create a results array and a temporary one // to hold the data $resultArray = array(); $tempArray = array(); // Loop through each row in the result set while($row = $result->fetch_object()) { // Add each row into our results array $tempArray = $row; array_push($resultArray, $tempArra
Replies
5
Boosts
0
Views
1.8k
Activity
Nov ’22
Reply to Error Domain=NSCocoaErrorDomain Code=3840 AND
my bad i forgot my code : import Foundation import UIKit protocol HomeModelDelegate { func itemsDowloaded(client:[Client] ) } class HomeModel : NSObject { var delegate:HomeModelDelegate? func getItems(){ //Hit the conn url let serviceURL = http://myFTPSERVER/service.php //Download the JSON Data let url = URL(string: serviceURL) if let url = url { // Create a URL Session let session = URLSession(configuration: .default) let task = session.dataTask(with: url) { (data, url, error) in if let data = data { //Succed print(data) //call the parseJson self.parseJson(data) }else{ } } // Start the task task.resume() } //notify the view controller and pass the data back } func parseJson(_ data:Data){ var clientArray = [Client]() do { //Parse the data into Client structs let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as! [Any] print(jsonArray) //loop through each result in the json array for jsonResult in jsonArray { //Cast json result as a dictionary let jsonDict = jsonResult as! [String:String
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’22
How to add an IBAction to a macOS tableView Cell
I have a macOS tableview I have a textfield as a column along with an IBAction code to capture the data from this field. I wanted to add continuous spell check for this column . So, I decided to change the column from a TextField to a ScrollView to take advantage of the continuous spell check. Using Xcode 14 I changed the Cell to a custom Cell. The custom cell has a scrollview object as the object because I want to take advantage of the built in continuous spell checking instead of using a textfield. All is well with this implementation until I tried to add a IBAction code for when I enter text in the scrollview/textView field. There does not seem to be a way to capture the text? Am I trying to do something that can't be done or is there a way to add continuous spell check to a textField?
Replies
4
Boosts
0
Views
1.4k
Activity
Nov ’22
Reply to How to add an IBAction to a macOS tableView Cell
To get access from the VC, you should, in the VC: create an IBOutlet for the tableView (not its container ScrollView) get a reference to the cell, with something like (adapt row and column values) guard let cell = tableView.view(atColumn: 0, row: 0, makeIfNecessary: true) as? CustomTableCell else { return } then use the cell to access any component you need: let text = cell.testTextView.textStorage?.string
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Nov ’22
Mac Catalyst: UINavigationController incorrectly blocks -setViewControllers:animated: call on UINavigationController when a transition/presentation is occurring on a different view controller.
I have a triple UISplitViewController. A UINavigationController is in the secondary column. When the selection changes in the supplementary column I call -setViewControllers:animated: and pass the navigation controller the new vc. I noticed sometimes the navigation view controller isn't updating and this logs out: setViewControllers:animated: called on while an existing transition or presentation is occurring; the navigation stack will not be updated. So this happens when the Split View controller itself is presenting another view controller modally (say a view controller with a UIActivityIndicatorView in it to show loading progress). But there is no transition/presentation occurring on the UINavigationController contained in the secondary view controller column itself. The presentation occurring on the UISplitViewController is completely separate and unrelated to the UINavigationController's navigation stack that's in the secondary column and therefore I should not be prev
Replies
1
Boosts
0
Views
783
Activity
Nov ’22
NavigationSplitView No Toggle Button
I went back to square one since the NavigationLink isActive is deprecated, this is when I found out about NavigationSplitView which removes the hassle of creating a 2 column app. However, I can never figure out why the toggle button does not show. I copied this sample code (already tried 2 tutorials, copy pasted them but still no toggle button) Anyone know why? import SwiftUI enum DemoScreen: String, Codable { case first, second, third var title: String { rawValue.capitalized } } struct ContentView: View { @State private var selection: DemoScreen? = .first var body: some View { NavigationSplitView { sidebarContent } detail: { detailContent } } } extension ContentView { var sidebarContent: some View { List { link(to: .first) link(to: .second) link(to: .third) } } func link(to page: DemoScreen) -> some View { NavigationLink(value: page) { Text(page.title) } } } extension ContentView { @ViewBuilder var detailContent: some View { if let selection = selection { detailContent(for: selection) .buttonStyl
Replies
1
Boosts
0
Views
932
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
Mac Catalyst: UISplitViewControllerColumnSecondary doesn't get key focus when the Tab Key is Pressed in a Triple UISplitViewController.
My UISplitViewController is configured like this: A list (collection view) is used in the primary view controller (sidebar style). When a selection is made in the primary view controller a table view displays data in the supplementary column. When a selection is made in the supplementary view controller, a view controller with scrollable content is shown in the secondary view controller. This is like the Mail app on Mac. So when I run the app I hit the tab key once and the list (collection view) in the primary column gets focus. I can navigate the list with the keyboard. This works as expected. So now with a selection in the list, a table view is showing in the supplementary column. I hit the tab key again and the table view gets focus. This works as expected as I can navigate the table view from the keyboard with the arrow keys. Now with a selection made in the table view, the scrollable view controller is showing in the secondary view controller column. I hit the tab key
Replies
3
Boosts
0
Views
917
Activity
Nov ’22
How to fix these errors?
Hello there! I want to create a cards game, and I'm creating it following the Stanford University's tutorial. I followed the video step by step but there is a warning that In the video doesn't appear. Can someone help me to fix it? Here's the link of the video: [https://www.youtube.com/watch?v=oWZOFSYS5GE&t=671s) This is my code: import SwiftUI struct ContentView: View { var emojis =[🚲,🚂,🚁,🚜,🚕,🏎,🚑,🚓,🚒,🚁,🚀,⛵️,🛸,🛶,🚌,🛺,🚇,🚠,🦽,🚗,🚚,🛴,🛵,🚅] @State var emojiCount: Int = 4 var body: some View { ScrollView { LazyVGrid(columns: [GridItem(), GridItem(), GridItem()]) { HStack { ForEach(emojis[0.. 1 { // here's the first error which says Cannot find 'emojiCount' in scope' emojiCount -= 1 // here's the same error which says Cannot find 'emojiCount' in scope' } } label: { Image(systemName: minus.circle) } } var add: some View { Button { if emojiCount < emojis.count { // here's the same error which says Cannot find 'emojiCount' in scope' emojiCount += 1 // here's the same error which says
Replies
4
Boosts
0
Views
629
Activity
Oct ’22
Reply to How to fix these errors?
Do you mean those warnings ? if emojiCount > 1 { // here's the first error which says Cannot find 'emojiCount' in scope' emojiCount -= 1 // here's the same error which says Cannot find 'emojiCount' in scope' } You're new to the forum, so welcome. And get a few advices: You'd better expose error messages clearly and not let others search for them in code… when you post code to avoid leaving 20 blank lines… Use Paste and Match Style and then code formatter tool. That will make your code easier to read. I noted several errors: var emojis = [🚲,🚂,🚁,🚜,🚕,🏎,🚑,🚓,🚒,🚁,🚀,⛵️,🛸,🛶,🚌,🛺,🚇,🚠,🦽,🚗,🚚,🛴,🛵,🚅] There need a space after =before [ var remove: some View { is defined out of struct ContentView: View { Hence, @State var emojiCount is not visible out of its scope (the struct). Probably, you have a misplaced closing parenthesis. This should be correct: import SwiftUI struct ContentView: View { var emojis = [🚲,🚂,🚁,🚜,🚕,🏎,🚑,🚓,🚒,🚁,🚀,⛵️,🛸,🛶,🚌,🛺,🚇,🚠,🦽,🚗,🚚,🛴,🛵,🚅] @State var emojiCoun
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’22