Post

Replies

Boosts

Views

Activity

Reply to Deselect list row in SwiftUI
Could you please show your code? I'm getting used to SwiftUI's declarative paradigm too so it's a little bit hard to adapt the code in the link from MacOS to iOS. Thanks in advance. Hello, I just removed the NavigationLinks, created the list options with a ForEach statement and the bottom one separately and called the views directly with if else statements, as I couldn't use a switch. I also wrapped the selected variable as a @state and created another one wrapped as @Binding, then I separated my views to make it more clear, readable and modular. That was all it needed to make it work!
Nov ’20
Reply to How can I have a variable that stores a few different struct types?
Hello OOPer, What I want is some way to be able to group some structs and then, a function to be able to receive as argument one of the structs (preferably it's type and not it's instance) in that group, do some calculations with it and then return it, but in a way that the code that called this function, would be able to get the type it wants without returning Any and then have to cast each of the results to the expected type. Example (I know that my example is a bit weird and complicated, but i would like to do something like this if possible. It's kind of a dynamic variable type): struct typeOne: TypeGroup { var id: Int = 0 var type: String = "test" var general: String = "test" static var descString: String = "This is a String" } struct typeTwo: TypeGroup { var id: Int = 0 var number: Int = 0 var general: String = "test" static var descNum: Int = 0 } struct typeThree: TypeGroup { var id: Int = 0 var kind: String = "test" var general: String = "test" static var descType: String = "This is a type" } func typeFunc(typee: TypeGroup) -> TypeGroup { /* Something like this: */ result: typeOf(typee) = typee.init() result.general = "Type: \( typee.descType)" /* or this: */ var result = typee.init() switch typeof(typee) { case typeOne: result.general = "String: \(typee.descString)" break case typeTwo: result.general = "Number: \(5 + typee.descNum)" break case typeThree: result.general = "Type: \( typee.descType)" break } return result } /* Then be able to do this: */ var typeResult: typeOne = typeFunc(typee: typeOne.Type) /* or this: */ var typeResult: typeTwo = typeFunc(typee: typeTwo.Type)
Dec ’20
Reply to How could I develop and deliver an offline library app with millions of images?
Hello Claude31, Thanks for the answer! I have tried to compress it, and from 17 GB it went down to 12 GB (which still is too much). The thing is, I cannot afford a server right now, and i didn't want the app to be dependent on this, so I think I will upload the files to a free cloud service (Google Drive maybe which has 15 GB free) and the first time the app opens, it will download the images as a zip, place them in the sandboxed user's directory, unzip it there and then grab the images from there. As for the performance, I am not exactly sure how I will deal with that, but I think I will add some kind of pagination.
Dec ’20
Reply to How can I have a variable that stores a few different struct types?
Hello OOPer, Your last answer indeed answers most of what I wanted. I forgot about the usage of Generics. My only remaining question which i am not sure if it has been answered, is if I could have a variable inside a struct of type T or TypeGroup that I could store inside any type of Test struct?? Example: struct TestStruct { var testType: TypeGroup = TestOne.Type /* This fails because the TestOne struct instance conforms to TypeGroup, but not the TestOne Type */ } func printTest (testStruct: TestStruct) { print(testStruct.testType.desc) } printTest(testStruct: TestStruct())
Dec ’20
Reply to Update a view from a button in another view.
Hello Claude31, Thanks for the answer! I searched for how I could use notifications to refresh my view, but all I found was about push and local notifications, shown in the notification center as a feedback to the user. I couldn't find something that would send an "internal" notification to the other view. Do you have a sample or a website, that explains how I could implement this, and also when the view receives the notification, how would it refresh?
May ’21
Reply to Update a view from a button in another view.
Thanks for the answer! I tried to apply this to my code, but i couldn't make it work. The problem is, I use SwiftUI and it's a SwiftUI app, so it does not have a viewDidLoad and it's also not a class but a struct, so i couldn't use the addObserver function. Also, I still haven't understood how am I going to refresh my view, as it's a navigation link that points to another view that has a viewBuilder struct with a list that returns the data in a closure variable. That view is like: Swift struct GroupListView: View {         var body: some View {                 VStack {                         /* Custom viewBuilder struct */                 FilteredList(parameters: viewModel.filterParameters) { (item: EntityItem) in                                 /* View for nicely displaying the rows */                                 /* (This view is the first one in my question description which has one of the buttons) */                         ListRow(rowValue: item)                 }                 }         } }
May ’21
Reply to Update a view from a button in another view.
Hello Claude31, I tried to make it work, but it didn't, so I added a workaround (which I don't really like, to be honest) which repeats some parts of the code two times based on the toggle of a Bool variable. Here is the repository for the project: GitHub Link - https://github.com/Chpetrou/StampJourney. If you know some other way to properly implement this, please inform me.
May ’21
Reply to Update a view from a button in another view.
I tried to create an app with full SwiftUI to see how it works and experiment a bit with it, but as you note, I also found out that it's inflexible, a bit limited and kind of immature at the moment. With UIKit you could do almost whatever you wanted, but my main issue, was with positioning the elements on the screen with constrains. I guess next time I'll merge UIKit with a few SwiftUI components to get the best of both. Anyway, thanks for the answers.
May ’21