Post

Replies

Boosts

Views

Activity

Reading (NS)Bundle in iOS after relaunch
Sorry, I did not have a catchier title: Prelude Avid followers of my Twitter account know: I was looking for an easy, preferably human editable container for documents, and — being the old Mac developer I am — I went with bundles, stored in the Documents folder. The Problem At some point in my app, the user can choose which file to use. And then, of course, on next launch, that file should be used. Selecting the file works all nice and well, including reading from the created Bundle. The problem occurs when the App is relaunched, and reads the absoluteString of the file from the UserDefaults. This works, and I can create a URL from it. But creating a bundle fails, and I don't get any error. This happens on iOS 15 and 16, on device and in the simulator. Is this some permissions things? Is the url not formatted correctly? What is going on? To Reproduce I have created a sample App here: https://github.com/below/BundleSample Launch the App, in the Simulator or on device Select "Copy Bundle" (You can "Test Resource Bundle", but it does not matter) Finally, select "Test Documents Bundle". You should see a picture Close the app, either by stopping it in Xcode or force quit Restart the App Expected Result You see the picture Acutal Result You see the "Gear" placeholder
3
0
1.4k
Sep ’22
Generics and AssociatedTypes
Sorry, I did not have a better title for this, I hope it gets clearer with code. The idea is to build a simple facade for Persistent Storage of some objects: class PersistantStorage<T, Codable, Identifiable> {     func store(_ object: T) throws { }          func objectFor(_ key: T.ID) -> T? {         return nil     } } As apparent, there is the generic type T, which is constrained to Codable and Identifiable. Now I want to use the later constraint to define my objectFor method, but the compiler complains: 'ID' is not a member type of type 'T' How would I do this? Or is this completely the wrong approach? Thanks Alex
1
0
1.6k
Jun ’22
@EnvironmentObject and Protocols?
I would like to declare an @EnvironmentObject as a protocol, namely as protocol AccessTokenProvider: Authenticator {     func accessToken() - AccessTokenPublisher } where Authenticator is public class Authenticator: NSObject, ObservableObject However, when I add this to the environment as var authenticator: AccessTokenProvider = MyAuthenticator() […] ContentView().environmentObject(authenticator) the compiler throws an error at: struct ContentView: View { // error: property type 'AccessTokenProvider' does not match that of the 'wrappedValue' property of its wrapper type 'EnvironmentObject'     @EnvironmentObject var authenticator: AccessTokenProvider                            ^ Is this even a good idea? If so, what am I doing wrong?                            ^
2
1
5.8k
May ’22
Lauch a Script (Python) app in ARM64
Today I was reminded that apps on the Mac do not have to be Mach-O Executables: They can be scripts! For example, a python script. But what I found out that if the app is started directly from the terminal, the app starts as ARM64. But if starting from the Finder (i.e. launchd), it is launched as Intel. Is there an Info.plist key that fixes this?
1
0
1.1k
Mar ’22
AVFoundation CaptureDevice and Mac virtual cameras
Hello, on Mac OS, is it possible to see a virtual Camera, such as OBS (https://obsproject.com) as a CaptureDevice? I see that, for example, Google Chrome can use this camera, but using AVCaptureDevice.DiscoverySession I am unable to see it. Am I doing wrong?     var deviceTypes: [AVCaptureDevice.DeviceType] = [.builtInMicrophone, .builtInWideAngleCamera]     #if os(OSX)     deviceTypes.append(.externalUnknown)     #else     deviceTypes.append(contentsOf: [.builtInDualCamera, .builtInDualWideCamera, .builtInTelephotoCamera, .builtInTripleCamera, .builtInTrueDepthCamera, .builtInUltraWideCamera])     #endif     let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: deviceTypes,         mediaType: nil, position: .unspecified)     result = discoverySession.devices.map { device in         device.localizedName     }
1
0
1.7k
Nov ’21
Request times out with iCloud Private Relay: Why?
We have our own backend, running on our own server. When iCloud Private Relay is enabled, the requests to the server time out. How can we find out what precisely is failing? TLS 1.3 is enabled on the backend finished with error [-1001] Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={_kCFStreamErrorCodeKey=-2102, NSUnderlyingError=0x281b0a3d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <CBAE9DA5-9988-4E55-A732-B759842E411F>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(     "LocalDataTask <CBAE9DA5-9988-4E55-A732-B759842E411F>.<1>" ), NSLocalizedDescription=The request timed out.,
2
0
1.4k
Nov ’21
Reading (NS)Bundle in iOS after relaunch
Sorry, I did not have a catchier title: Prelude Avid followers of my Twitter account know: I was looking for an easy, preferably human editable container for documents, and — being the old Mac developer I am — I went with bundles, stored in the Documents folder. The Problem At some point in my app, the user can choose which file to use. And then, of course, on next launch, that file should be used. Selecting the file works all nice and well, including reading from the created Bundle. The problem occurs when the App is relaunched, and reads the absoluteString of the file from the UserDefaults. This works, and I can create a URL from it. But creating a bundle fails, and I don't get any error. This happens on iOS 15 and 16, on device and in the simulator. Is this some permissions things? Is the url not formatted correctly? What is going on? To Reproduce I have created a sample App here: https://github.com/below/BundleSample Launch the App, in the Simulator or on device Select "Copy Bundle" (You can "Test Resource Bundle", but it does not matter) Finally, select "Test Documents Bundle". You should see a picture Close the app, either by stopping it in Xcode or force quit Restart the App Expected Result You see the picture Acutal Result You see the "Gear" placeholder
Replies
3
Boosts
0
Views
1.4k
Activity
Sep ’22
Generics and AssociatedTypes
Sorry, I did not have a better title for this, I hope it gets clearer with code. The idea is to build a simple facade for Persistent Storage of some objects: class PersistantStorage<T, Codable, Identifiable> {     func store(_ object: T) throws { }          func objectFor(_ key: T.ID) -> T? {         return nil     } } As apparent, there is the generic type T, which is constrained to Codable and Identifiable. Now I want to use the later constraint to define my objectFor method, but the compiler complains: 'ID' is not a member type of type 'T' How would I do this? Or is this completely the wrong approach? Thanks Alex
Replies
1
Boosts
0
Views
1.6k
Activity
Jun ’22
@EnvironmentObject and Protocols?
I would like to declare an @EnvironmentObject as a protocol, namely as protocol AccessTokenProvider: Authenticator {     func accessToken() - AccessTokenPublisher } where Authenticator is public class Authenticator: NSObject, ObservableObject However, when I add this to the environment as var authenticator: AccessTokenProvider = MyAuthenticator() […] ContentView().environmentObject(authenticator) the compiler throws an error at: struct ContentView: View { // error: property type 'AccessTokenProvider' does not match that of the 'wrappedValue' property of its wrapper type 'EnvironmentObject'     @EnvironmentObject var authenticator: AccessTokenProvider                            ^ Is this even a good idea? If so, what am I doing wrong?                            ^
Replies
2
Boosts
1
Views
5.8k
Activity
May ’22
Lauch a Script (Python) app in ARM64
Today I was reminded that apps on the Mac do not have to be Mach-O Executables: They can be scripts! For example, a python script. But what I found out that if the app is started directly from the terminal, the app starts as ARM64. But if starting from the Finder (i.e. launchd), it is launched as Intel. Is there an Info.plist key that fixes this?
Replies
1
Boosts
0
Views
1.1k
Activity
Mar ’22
AVFoundation CaptureDevice and Mac virtual cameras
Hello, on Mac OS, is it possible to see a virtual Camera, such as OBS (https://obsproject.com) as a CaptureDevice? I see that, for example, Google Chrome can use this camera, but using AVCaptureDevice.DiscoverySession I am unable to see it. Am I doing wrong?     var deviceTypes: [AVCaptureDevice.DeviceType] = [.builtInMicrophone, .builtInWideAngleCamera]     #if os(OSX)     deviceTypes.append(.externalUnknown)     #else     deviceTypes.append(contentsOf: [.builtInDualCamera, .builtInDualWideCamera, .builtInTelephotoCamera, .builtInTripleCamera, .builtInTrueDepthCamera, .builtInUltraWideCamera])     #endif     let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: deviceTypes,         mediaType: nil, position: .unspecified)     result = discoverySession.devices.map { device in         device.localizedName     }
Replies
1
Boosts
0
Views
1.7k
Activity
Nov ’21
Request times out with iCloud Private Relay: Why?
We have our own backend, running on our own server. When iCloud Private Relay is enabled, the requests to the server time out. How can we find out what precisely is failing? TLS 1.3 is enabled on the backend finished with error [-1001] Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={_kCFStreamErrorCodeKey=-2102, NSUnderlyingError=0x281b0a3d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <CBAE9DA5-9988-4E55-A732-B759842E411F>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(     "LocalDataTask <CBAE9DA5-9988-4E55-A732-B759842E411F>.<1>" ), NSLocalizedDescription=The request timed out.,
Replies
2
Boosts
0
Views
1.4k
Activity
Nov ’21