Post

Replies

Boosts

Views

Activity

How to store custom binary data in app?
I'm using SwiftUI to create an IOS application. I have some binary files that I need to read from within the application. What is the best way to add these files to my application? I can always convert them to constant binary arrays in a swift file, but that seems a bit silly to me. I'd much prefer to load the binary file from the bundle (bundle.main.path()) if that's possible. I just can't figure out how to get the files added to the bundle. I'm using XCode 14.3.1 if it matters.
1
0
1.1k
Aug ’23
UInt64 and shifts
I must be missing something simple here. I have an application I'm writing and having trouble with shifts and 64 bit unsigned integers. Here's some playground code: import UIKit let a: UInt64 = 0xFFFFFFFF00000000 let b: UInt64 = 0x0000000000000000 print(String(format: "a = 0x%016X", a)) print(String(format: "b = 0x%016X", b)) print(String(format: "a | b = 0x%016X", a | b)) It produces this output: a = 0x0000000000000000 b = 0x0000000000000000 a | b = 0x0000000000000000 Why is "a" not equal to 0xFFFFFFFF00000000? I'm using XCode 14.3.1. I also found issues shifting a byte into the upper 32 bits of a UInt64: let c: UInt64 = 0x00000000000000FF let d: UInt64 = 0x0000000000000000 print(String(format: "c = 0x%016X", c)) print(String(format: "d = 0x%016X", d)) print(String(format: "d | (c << 32) = 0x%016X", d | (c << 32))) This produces this output: c = 0x00000000000000FF d = 0x0000000000000000 d | (c << 32) = 0x0000000000000000
1
0
342
Jul ’23
Master-Detail with CoreData in SwiftUI?
I have been trying to get a master detail application working for too long. I've tried many things and nothing really seems to work. Part of my problem is that I don't know the best way to go about it. I have a core data model created and I can add master items. I have a detail view in a tab view that should display the detail items for the global selected master (optional value on environment object data). The questions I have are: What is the best way to do a detail view with a list? Iterate over the master object's list of detail items or use a fetch request with a predicate for the master? The first way kinda seems to work but the list doesn't get updated when items are deleted. It's not clear to me how to do the predicates for the fetch request so I haven't figured that out yet. When deleting detail items, how is this done? Do you delete from the master and then save? Do you delete the detail items and let core data take care of the master? Is there some other way? Does anybody know of a decent example of this kind of thing. All the examples I found either don't do editing, don't use core data, etc. I'm not posting code because I'm trying to figure out best practices and what is recommended by Apple. Thanks.
3
0
2.1k
Jun ’22
Measurement Class angle measurement
I created a variable like so: var d = Measurement(Value: 360.0, unit: UnitAngle.degrees) When I print it converted to arcMinutes: print(d.converted(to: UnitAngle.arcMinutes).value) I get 21599.568008639824 which is off by about a half an arc minute. If I create my own unit "moa" extension { public static moa = UnitAngle(symbol: "moa", converter: UnitConverterLinear(coefficient: 1.0/60.0)) } and then print it in moa: print(d.converted(to: UnitAngle.moa).value) I get 21600.0 as I would expect. I have seen posts on StackOverflow dating back to 2018 discussing this. I guess it's still broken? This was run on Xcode, Version 11.6. I apologize if there are any typos in the code, I didn't run it on this computer, so I had to retype it.
3
1
689
Jul ’20