Post

Replies

Boosts

Views

Activity

For Loop Conversion in Swift
Hi, i have only seen for loop samples that involve indexes or using for item in items. I come from a java background and i cannot seem to confirm if this can actually be converted to a swift for loop. thoughts? for (EdgeNode edge = aet.topNode ; (edge != null); edge = edge.next)
1
0
585
Feb ’23
How to set instance of a property of the same class type
See sample class class A { var proxy: A init () { proxy = self } } In Java, i could do something like this class A { A proxy; A () { proxy = this } } so when i instantiate A sample = new A(); the proxy variable will be set to the "this" keyword. But in Swift, the only related keyword to it is self but it does not behave the same way. It merely serves somewhat of a pointer to properties and methods that it belongs to it. Is this possible in Swift? if yes, how to go about this? I could not find any solution (perhaps because there is a term for that style? which I have no clue about) thoughts?
1
0
595
Feb ’23
Why does date only object always has 16:00:00 time? instead of 00:00:00
So ive read there is no feature in the Foundation package that outputs a date only object. Ive tried variations seen in forum posts. One of them is like this. But i am confused why the output is always 16:00:00 +0000 for the time instead of 00:00:00 +0000? This is the code Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: Date())! 16:00:00 is 4PM. Instead of 12:00AM When I run it in this site online swift playground https://online.swiftplayground.run/ i get this output 2023-02-26 23:00:00 +0000 I figure this could be because of timezone. But is there a way to get a date object where the value of time is midnight? 00:00:00? Thoughts?
1
0
661
Feb ’23
Build Input File Cannot Be Found .app
This one is about the .app not found. I am not sure why. And i have not seen a post about a .app not being found. Build input file cannot be found: '.../DerivedData/...../Build/Products/Debug-iphonesimulator/......app/.....'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? Thoughts what could be wrong?
1
0
951
Mar ’23
touch events do not work in ipad air and pro
what happened? i never noticed it until i decided to use ipad air and pro as option in chrome dev console mobile view as well as ios simulator. it works ok in the ipad mini. touch events do not get triggered. instead, the scroll seems to overlap these. EDIT: Solved. please see comment below. While it works ok in ipad pro devices now, I still wish this could work out in chrome's dev console ipad pro view. the behavior is different with click events. instead of mouse down, it starts with mouse move. what gives? this only happens in ipad air and pro view in the device toolbar in dev console.
1
0
994
Jan ’24
How To Make Optional Variables in SwiftUI View
Please see sample code struct Test: View { var array: [String] = [] init() { } var body: some View { Text(String(description: array.count) } } struct Test_Previews: PreviewProvider { static var previews: some View { Test(array: ["1", "2", "3"]) } } This one is a string array, I wish to pass some values only in preview because in the main view, i will be fetching data from a url. While setting this variable array to an empty array is the solution, what if my variable is a Struct? or Class? How will i make this optional and only supply a new Struct/Class instance in the preview only
2
0
994
Sep ’22
Help Setting Google Maps
Hi all. I have not found a solution to this. Showing Recent Issues GoogleMaps.xcframework' is missing architecture(s) required by this target (arm64), but may still be link-compatible. So many posts saying go to Build Settings and in debug/release exclude arm64 but there is none here. I am using xcode 13.4.1 Anyone got ideas?
2
0
700
Oct ’22
How To Create a Marker With Callout in MapKit SwiftUI
I have not seen a tutorial that shows a callout when a marker is clicked in the map. Can anyone please confirm? Weird that this feature is not included. The callout I need is just a simple title and subtitle. That's all. Tutorials only show how to render using MapMarker, MapPin and custom MapAnnotations but these do nothing since they only show icons.
2
0
532
Oct ’22
Using if condition in Kingfisher.shared.retrieveImage
Hi. This short code for Kingfisher goes like this KingfisherManager.shared.retrieveImage(with: ImageResource(downloadURL: URL(string: "URL HERE")!)) { result in           switch result {             case .success(let value):                             break             default:               break           }         } I am actually interested in .success only but if i remove default it will show an error message like Switch must be exhaustive. How to make this an if statement that goes something like this if result == .success { how to get value in scope here so i can use it. thoughts? }
2
0
866
Oct ’22
Merge An Array Item's Array Property Based On Property
The title might be confusing but here is an example data to give a clear understanding struct City { var name: String? var businesses: [Business]? } So if i have a city array, i wish to merge the businesses array based on the city name since the city may have duplicates e.g. [ { name: "CIty 1" businesses: [ { name: "Business 1" }, { name: "Business 2" }, ] }, { name: "CIty 2" businesses: [ { name: "Business 1" }, { name: "Business 2" }, ] } { name: "CIty 1" businesses: [ { name: "Business 3" }, { name: "Business 4" }, ] } ] In the data example above, there are 2 entries of City1. i am looking for a way to not have to use a dictionary, if it is possible to use the existing array and output it such that there is only 1 entry of City but will contain 4 entries of business. Thoughts?
2
0
411
Oct ’22
How to Resize Placeholder in Kingfisher where loading icon is in the middle
Hi. Please see screenshot. Currently the icon placeholder is small. What I am trying to replicate is to have an area (the one in red) where the place holder icon is in the middle horizontally and vertically. That same red area is where the downloaded image will be drawn. I think the term for this is aspect ratio if i am not mistaken? That the height should be proportionate based on the width. I am using Kingfisher to load the image. This is what I have. KFImage.url(URL(string: ""))             .placeholder {               HStack {                 Image(systemName: "photo")                   .resizable()                   .frame(width: 50, alignment: .center)                                       .background(.red)               }               .background(.yellow)               .scaledToFit()             }             .fade(duration: 0.25)             .onFailure { error in print("Load image error : \(error) = \(earthquakeDetail.imgUrl)")             }             .resizable()             .aspectRatio(contentMode: .fill) Based on the screenshot image, the area for HStack is so thin with its height being small. My goal is to create an area like the one in red border. Thoughts?
2
0
1.6k
Oct ’22
Why Is Bottom Sheet Full Screen? What is the workaround for Dynamic Height?
Hi. Beginner here. I am looking at bottom sheet and it is frustrating that the result is always full screen. Sure, in iPad it gets displayed as a modal dialog. I wonder why they just let it behave like that in the iPhone. The sheet should resize. based on the contents. What is your workaround for this? Should I still use sheet? or do it some other way using something else? I looked at .presentationDetents() but i can only set a fixed height to it. My content can be either 3,4,5,6,7... lines of Text() so my goal is to make the sheet height based on the contents inside it. Thoughts, ideas welcome.
2
0
2.2k
Oct ’22
Why Not Every Part Of View Is Clickable In NavigationLink
My navigation link looks like this struct ContentView: View { var body: some View {     NavigationView {       GeometryReader { geometryProxy in         NavigationLink {             EmptyView() // Any view         }         label: {           TestView(geometryProxy: geometryProxy)               .buttonStyle(.plain)                .padding(.leading, 8)         }         .buttonStyle(.plain)         .padding(.leading, 0)       }     }   } } And my test view looks like this struct TestView: View { var geometryProxy: GeometryProxy       var body: some View {     HStack {       Text("Some text here extra space on right")         .frame(maxWidth: geometryProxy.size.width * 0.85, alignment: .leading)       HStack {         Text("9.4")           .lineLimit(2)           .padding(8)       }       .frame(maxWidth: geometryProxy.size.width * 0.15)       .padding([.top, .bottom], 4)     }   } } Because there is some gap between the text "Some text here extra space on right" and "9.4", when that area gets tapped nothing happens. NavigationLink will only work when any text is tapped. Why is that? What is lacking here that will make any view in the TestView cllickable, including empty space.
2
0
1.1k
Oct ’22
"Invalid top-level type in JSON write"
I have seen posts about this error message but i am making a new one because my case is different. the json is valid. so i have no clue why it gives out this error. Sample json here i removed the forward slash so it will be clean since when i do a print() it always shows as "key": "value" this is the code i use to convert it to data then it gives out that error. i checked the json in online json validator sites and it's good. let string = the json string from the url above let jsonObject = try? JSONSerialization.data(withJSONObject: string, options: []) It is supposed to be a json array. any idea why the error?
2
0
3.1k
Nov ’22