Post

Replies

Boosts

Views

Activity

Will 2 environmentObject work?
Ive read posts where you can pass 2 .environmentObject() but what i noticed is that if i call object1.objectWillChange.send() , object2 also is affected is this normal? or supposedly only published properties of object1 only gets affected? discussion quwstion. thoughts?
1
0
425
Dec ’22
How To Fix CoreData: error: Failed to load mode model named ...
Hi. I have no clue what I am doing wrong or am i missing something else. I keep getting the error message CoreData: error: Failed to load model named DMTideCity Please see attached image for data model. My goal is just to load this but I dont know why I keep getting that error message. struct TideDataController {       static let shared = TideDataController()   let cityContainer: NSPersistentContainer       init() {     print("init")     cityContainer = NSPersistentContainer(name: "DMTideCity")     print(cityContainer)     cityContainer.loadPersistentStores { description, error in       if let error {         print("Core Data Citys failed to load: \(error.localizedDescription)")       }       else {         print("Core Data Citys loaded")       }     }   } } In my view, i declare a variable like this let tideDataController = TideDataController.shared So it never reaches the print(cityContainer) because of that error message. Thoughts?
1
0
1.8k
Dec ’22
Why Doesnt this Wrap Correctly?
struct TideForecastInfoView: View {       var geometryProxy: GeometryProxy       var body: some View {     VStack {       getHeaders(geometryProxy)               TideForecastEntryView(geometryProxy: geometryProxy)           .padding(2)     }     .background(.white)     .clipShape(RoundedRectangle(cornerRadius: 14))     .shadow(radius: 8)   }       @ViewBuilder   func getHeaders(_ geometryProxy: GeometryProxy) -> some View {     HStack {       HStack {         Text("tide")           .frame(maxWidth: geometryProxy.size.width * 0.25)         Text("time")           .frame(maxWidth: geometryProxy.size.width * 0.5)         Text("height")           .frame(maxWidth: geometryProxy.size.width * 0.25)       }       .padding(8)     }     .frame(maxWidth: .infinity)     .background(.gray)   }   } struct TideForecastEntryView: View {       var geometryProxy: GeometryProxy       var body: some View {     HStack {       Text("High Tide")         .frame(maxWidth: geometryProxy.size.width * 0.25)       Text("1:08 AM (Tue 03) January")         .frame(maxWidth: geometryProxy.size.width * 0.5, alignment: .leading)       Text("1.31 m (4.3 ft)")         .frame(maxWidth: geometryProxy.size.width * 0.25)     }   } } Result looks like this 03 should be on the first line and maybe parts of the January word. is there something else missing in the Text view option that i need to declare? Also how to vertical align top for text High Tide. it is always vertically centered. I tried to set alignment: .top in the frame but doesnt do anything. Thoughts?
1
0
794
Jan ’23
How To Create Data Json Object from Empty String
This is what I tried to do. I am not sure what is wrong. anyone got ideas? let data: Data? = try? JSONSerialization.data(withJSONObject: "") and it says reason: '*** +[NSJSONSerialization dataWithJSONObject:options:error:]: Invalid top-level type in JSON write' even if i put in "{}" error is the same. thoughts? Purpose for this is i want set this to a URLRequest.httpBody Thoughts?
1
0
1.2k
Jan ’23
Possible to set body view's background to transparent?
Please see screenshot. Currently the one in white has an animation in the middle. i wish to set the background of the body's view to transparent so that only the animation from my app is visible (it's like the home screen but only my animation is shown when the app is run. Is that possible? I tried to set VStack's background color opacity to 0 but nothing happpens. Or is it something else that needs to be modified? Thoughts?
1
0
710
Jan ’23
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
596
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
Possible to have 2 let variables in 1 if condition?
I am converting Java code to Swift. This is the Java code try { if (filter == null || Float.parseFloat(ew.getMagnitude()) >= Float.parseFloat(filter)) liist.add(ew); } catch (NumberFormatException e) { } In Swift, currently this is what I have do {                     if let toFilter = filter, Float(ew.magnitude ?? "0") >= Float(toFilter ?? "0") {                           list.append(ew)                       }                     }                     else {                       list.append(ew)                     }                   } catch {                                        } Currently it even gives out an error that I have to add a ! after the Float() because "Force-unwrap using '!' to abort execution if the optional value contains 'nil'" But i do not want that, that is why I placed th do/catch there Please enlighten. Thank you
0
0
248
Sep ’22
Convert Date From Timezone
Hi, this is my function I cannot figure out why i always get jan 1, 2000 [time...] this is my code if let thisTime = Int64(time) {     let date = Date(timeIntervalSince1970: TimeInterval(thisTime) / 1000)     let dateWithTimezone = convertStringToDateWithTimezone(date)     print(formatDate(dateWithTimezone, "hh:mm a")!) } The date variable is correct but once I use convertStringToDateWithTimezone the result is always jan 1, 2000 [time...] Any idea what could be wrong?   func convertStringToDateWithTimezone(_ d: Date) -> Date {     let dateFormatter = DateFormatter()     dateFormatter.timeZone = TimeZone.current     return dateFormatter.date(from: (dateFormatter.string(from: d)))!   } func formatDate(_ date: Date?, _ pattern: String) -> String? {     if let date = date {       let dateFormatter = DateFormatter()       dateFormatter.locale = Locale(identifier: "en")       dateFormatter.dateFormat = pattern       return dateFormatter.string(from: date)     }     return nil   }
0
0
314
Sep ’22
Adding Custom InfoWIndow In Google Maps SDK In SwiftUI
Hi all. Came here as a last resort. All the samples provided that I came across are not in SwiftUI. Google's documentation is also outdated since they do not provide any samples or tutorial to do so in SwiftUI. While showing the map in SwiftUI requires you to extend a UIViewRepresentable, i have no clue how to apply the custom info window with it. Anyone got suggestions?
0
0
514
Oct ’22
Import An Objective-C Library To A Swift Project
All posts i came across instructs the user to import the objective c files into the swift project so that a bridging header file can be created to expose it. Does this mean i have to instead download the objective c library, extract and copy all the files to the swift project? where the prompt to create the bridging header will be triggered? Or is there a way to install the objective c library via cocoapods and manually trigger to create the bridging header to make it usable? I prefer the latter, if it is possible?
0
0
413
Oct ’22