Posts

Post not yet marked as solved
0 Replies
142 Views
I got a @Model class with a property of a codable "Options" struct. import SwiftData @Model final class Project { var options: Options } In this struct I have another property called "resolution" of type Size3D. import Spatial struct Options: Codable { var resolution: Size3D } I can initially launch the app and save a project with a custom resolution. Tho when I try to re-launch the app it crashes: Could not cast value of type 'Swift.Optional<Any>' (0x1fa251d80) to '__C.SPSize3D' (0x1047dcbc0). Size3D is codable, tho it does not seem to currently be supported by SwiftData. My current solution is to have a middle type that I store in my options struct like this: struct Options: Codable { private struct CodableResolution: Codable { let width: Double let height: Double let depth: Double var size: Size3D { Size3D(width: width, height: height, depth: depth) } init(_ size: Size3D) { self.width = size.width self.height = size.height self.depth = size.depth } } private var codableResolution: CodableResolution var resolution: Size3D { get { codableResolution.size } set { codableResolution = CodableResolution(newValue) } } } Note that I'm testing this on the visionOS simulator with Xcode 15.2 on macOS 14.0 Feedback: FB13543953
Posted
by Heestand.
Last updated
.
Post not yet marked as solved
5 Replies
2.4k Views
Hi, I want to subclass my model. Here is my superclass: import SwiftData @Model public class Control { @Attribute(.unique) public var frame: Frame init(frame: Frame) { self.frame = frame } } Here is my subclass: import SwiftData import CoreGraphics class SliderControl: Control { let axis: Axis var value: CGFloat = 0.0 init(axis: Axis, frame: Frame) { self.axis = axis super.init(frame: frame) } required public init(backingData: any BackingData<Control>, fromFetch: Bool = false) { // How to get `axis` and `value` from the backing data? } } I'm not sure how to use the backing data to re-create my object. My goal is to have multiple controls with unique properties.
Posted
by Heestand.
Last updated
.
Post marked as solved
8 Replies
5.8k Views
Hi, I've got a Swift Framework with a bunch of Metal files. Currently users have to manually include a Metal Lib in their bundle provided separately, to use the Swift Package. First question; Is there a way to make a Metal Lib target in a Swift Package, and just include the .metal files? (without a binary asset) Second question; If not, Swift 5.3 has resource support, how would you recommend to bundle a Metal Lib in a Swift Package?
Posted
by Heestand.
Last updated
.
Post marked as solved
1 Replies
757 Views
I'm trying to use the new layerEffect(_:maxSampleOffset:isEnabled:). https://developer.apple.com/documentation/swiftui/view/layereffect(_:maxsampleoffset:isenabled:) Tho I'm not sure how to define the metal shader function signature. The docs indicate that we should use SwiftUI::Layer, tho I'm not sure what to import to get access to this layer structure. [[ stitchable ]] half4 name(float2 position, SwiftUI::Layer layer, args...) My goal is to create a custom blur effect. Does anyone have any pointer on how to get started with layer effects?
Posted
by Heestand.
Last updated
.
Post not yet marked as solved
0 Replies
1.7k Views
I've got a Multiplatform app with a SwiftUI view and this function: .onDrop(of: [.image], delegate: myController) In an extension of my controller I conform to the DropDelegate and implement performDrop(info:) I've also typealias'ed the Image types. #if os(macOS) public typealias MPImage = NSImage #else public typealias MPImage = UIImage #endif Here's my implementation: guard info.hasItemsConforming(to: [.image]) else { return false } let items: [NSItemProvider] = info.itemProviders(for: [.image]) guard let item: NSItemProvider = items.first else { return false } guard item.canLoadObject(ofClass: MPImage.self) else { return false } item.loadObject(ofClass: MPImage.self) { (reading, error) in &#9;&#9;guard error == nil else { return } &#9;&#9;guard let image: MPImage = reading as? MPImage else { return } &#9;&#9;self.didLoad(image: image) } This compiles fine on iOS, tho on macOS I get the following errors: Instance method 'canLoadObject(ofClass:)' requires that 'MPImage' (aka 'NSImage') conform to 'ObjectiveCBridgeable' and Instance method 'loadObject(ofClass:completionHandler:)' requires that 'MPImage' (aka 'NSImage') conform to 'ObjectiveCBridgeable' Is this not the way to do drag and drop on macOS?
Posted
by Heestand.
Last updated
.
Post not yet marked as solved
0 Replies
843 Views
I've got a multi-platform document based app, with package files (the "file" is a folder, but looks like a file for the user). I can create files on all platforms, tho I can only open files on Mac and iPhone. When I try to open files (in iCloud) on iPad, the file does not open and nothing is logged. Tho the files do open when they are stored locally on the iPad. I followed the documentation here: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/DocumentPackages/DocumentPackages.html I've specified LSTypeIsPackage to true and added com.apple.package to UTTypeConformsTo. I've tried incrementing the build number. I'm targeting iOS 14 / macOS 11, and build with Xcode 13 beta 3. Here's my info.plist: &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;CFBundleDocumentTypes&lt;/key&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;CFBundleTypeName&lt;/key&gt; &lt;string&gt;File Name&lt;/string&gt; &lt;key&gt;LSHandlerRank&lt;/key&gt; &lt;string&gt;Owner&lt;/string&gt; &lt;key&gt;LSItemContentTypes&lt;/key&gt; &lt;array&gt; &lt;string&gt;com.mysite.file&lt;/string&gt; &lt;/array&gt; &lt;key&gt;LSTypeIsPackage&lt;/key&gt; &lt;true/&gt; &lt;/dict&gt; &lt;/array&gt; &lt;key&gt;LSRequiresIPhoneOS&lt;/key&gt; &lt;true/&gt; &lt;key&gt;LSSupportsOpeningDocumentsInPlace&lt;/key&gt; &lt;true/&gt; &lt;key&gt;UISupportsDocumentBrowser&lt;/key&gt; &lt;true/&gt; &lt;key&gt;UIFileSharingEnabled&lt;/key&gt; &lt;true/&gt; &lt;key&gt;UTExportedTypeDeclarations&lt;/key&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;UTTypeConformsTo&lt;/key&gt; &lt;array&gt; &lt;string&gt;com.apple.package&lt;/string&gt; &lt;string&gt;public.composite-content&lt;/string&gt; &lt;string&gt;public.data&lt;/string&gt; &lt;/array&gt; &lt;key&gt;UTTypeDescription&lt;/key&gt; &lt;string&gt;File Name&lt;/string&gt; &lt;key&gt;UTTypeIdentifier&lt;/key&gt; &lt;string&gt;com.mysite.file&lt;/string&gt; &lt;key&gt;UTTypeTagSpecification&lt;/key&gt; &lt;dict&gt; &lt;key&gt;public.filename-extension&lt;/key&gt; &lt;array&gt; &lt;string&gt;myext&lt;/string&gt; &lt;/array&gt; &lt;/dict&gt; &lt;/dict&gt; &lt;/array&gt; &lt;/dict&gt; &lt;/plist&gt; Does anyone know how to debug this?
Posted
by Heestand.
Last updated
.
Post not yet marked as solved
0 Replies
1.6k Views
Hi I'm using this package in an app. The package builds fine. Tho I get build errors in the package when I build the app. Here's the error I get: Main actor-isolated class 'My Class' has different actor isolation from nonisolated superclass 'My Super Class' I'm not using actor or @MainActor, so I'm not sure where the error is coming from. Here's a line where the error shows up in the package. Related stackoverflow post.
Posted
by Heestand.
Last updated
.
Post not yet marked as solved
1 Replies
1.1k Views
I'm adding pointer interactions to my app.if #available(iOS 13.4, *) { let interaction = UIPointerInteraction(delegate: self) button.addInteraction(interaction) }@available(iOS 13.4, *) func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -&gt; UIPointerStyle? { UIPointerStyle(effect: .lift(UITargetedPreview(view: button)), shape: .roundedRect(button.frame, radius: ViewAssistant.buttonCornerRadius)) }I get this exception sometimes, not sure why?Thread 1: Exception: "UIPreviewTarget requires that the container view is in a window, but it is not. (container: &lt;UIView: 0x10873d800&gt; =&gt; &lt;UIScrollView: 0x108873c00&gt; =&gt; &lt;_UIVisualEffectContentView: 0x108745070&gt; =&gt; &lt;Pixel_Nodes.PanelCreatorView: 0x108727ad0&gt;)"
Posted
by Heestand.
Last updated
.
Post not yet marked as solved
0 Replies
489 Views
Hey, We found an issue, or it's actually know, check the stackoverflow link. Our Core ML model's auto generated Swift code does not compile. On macOS 11.0 Beta (20A5395g) with Xcode Version 12.0 (12A7209) https://stackoverflow.com/questions/63917164/ml-build-error-for-catalyst-xcode-12-gm
Posted
by Heestand.
Last updated
.
Post not yet marked as solved
2 Replies
4.4k Views
I've got a SwiftUI app with the onDrop method on my View like this: .onDrop(of: [.image], delegate: myController) In an extension of my controller I conform to the DropDelegate and implement performDrop(info:) Here's my implementation: guard info.hasItemsConforming(to: [.image]) else { return false } let items: [NSItemProvider] = info.itemProviders(for: [.image]) guard let item: NSItemProvider = items.first else { return false } guard item.canLoadObject(ofClass: MPImage.self) else { return false } item.loadObject(ofClass: MPImage.self) { (reading, error) in guard error == nil else { return } guard let image: MPImage = reading as? MPImage else { return } self.didLoad(image: image) } The code compiles fine on iOS (tho not on macOS, see link) https://developer.apple.com/forums/thread/653934 So when I run the app on iOS, and drag an image from Photos and drop it on my app I get the following error: MyApp perform drop failed: Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.jpeg" UserInfo={NSLocalizedDescription=Cannot load representation of type public.jpeg, NSUnderlyingError=0x283fa15f0 {Error Domain=NSCocoaErrorDomain Code=260 "The file “DAE533E7-2918-465E-9F3C-502B8DEC78BA.jpeg” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///var/tmp/com.apple.DragUI.druid/.com.apple.DragUI.BDfAeP/DAE533E7-2918-465E-9F3C-502B8DEC78BA.jpeg, NSFilePath=/var/tmp/com.apple.DragUI.druid/.com.apple.DragUI.BDfAeP/DAE533E7-2918-465E-9F3C-502B8DEC78BA.jpeg, NSUnderlyingError=0x283f4b8a0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}}}
Posted
by Heestand.
Last updated
.
Post not yet marked as solved
1 Replies
709 Views
I've got a Multiplatform SwiftUI app and I'm trying to create a hierarchical structure with OutlineGroup. My code works fine on iOS. Tho on macOS I get a crash. List { &#9;&#9;Section(header: Text("A")) { &#9;&#9;&#9;&#9;OutlineGroup(layers.aLayers, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; children: \.children) { layer in &#9;&#9;&#9;&#9;&#9;&#9;LayerView(layer: layer, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;selectedID: $layers.id) &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;Section(header: Text("B")) { &#9;&#9;&#9;&#9;OutlineGroup(layers.bLayers, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; children: \.children) { layer in &#9;&#9;&#9;&#9;&#9;&#9;LayerView(layer: layer, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;selectedID: $layers.id) &#9;&#9;&#9;&#9;} &#9;&#9;} } .listStyle(SidebarListStyle()) Does anyone know what this means? Thread 1: Fatal error: Could not find child #1 for Optional(SwiftUI.OutlineItem(id: SwiftUI.ViewListID.Canonical(_index: 0, implicitID: 0, explicitID: nil), isGroupItem: true))
Posted
by Heestand.
Last updated
.
Post marked as solved
3 Replies
991 Views
Hi, it seems the AVCaptureDevice is not available in an iOS project via Mac Catalyst. The official AVCam demo project also crashes while running via Mac Catalyst. Dose anyone know a solution to get a live camera feed?
Posted
by Heestand.
Last updated
.
Post not yet marked as solved
2 Replies
743 Views
I've start editing an image in Photos on macOS with my extension, and then when I try to save, I get an alert saying something went wrong when saving. func finishContentEditing(completionHandler:) In the finish content editing method I save my photo async like this: let output = PHContentEditingOutput(contentEditingInput: input) let unitCrop: UnitCrop = UnitCrop(frame: self.cropper.frame) do { &#9;&#9;let data: Data = try JSONEncoder().encode(unitCrop) &#9;&#9;output.adjustmentData = PHAdjustmentData(formatIdentifier: UnitCrop.formatIdentifier, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; formatVersion: UnitCrop.formatVersion, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; data: data) } catch { &#9;&#9;completionHandler(nil) &#9;&#9;return } self.cropper.save { result in &#9;&#9;switch result { &#9;&#9;case .success(let image): &#9;&#9;&#9;&#9;guard let imageData: Data = image.pngData() else { &#9;&#9;&#9;&#9;&#9;&#9;completionHandler(nil) &#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;do { &#9;&#9;&#9;&#9;&#9;&#9;try imageData.write(to: output.renderedContentURL, options: .atomic) &#9;&#9;&#9;&#9;&#9;&#9;print("success!") &#9;&#9;&#9;&#9;&#9;&#9;completionHandler(output) &#9;&#9;&#9;&#9;} catch { &#9;&#9;&#9;&#9;&#9;&#9;completionHandler(nil) &#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;} &#9;&#9;case .failure(let error): &#9;&#9;&#9;&#9;completionHandler(nil) &#9;&#9;} } I see the success print, tho I still get an popup alert saying it failed in Photos and no edits gets saved. Do anyone know how to debug this?
Posted
by Heestand.
Last updated
.
Post not yet marked as solved
2 Replies
1.4k Views
I'm making a Mac Catalyst app and have some 16 bit metal textures I would like to convert to an array of the new Float16. Tho it dose not seem to be available... 'Float16' is unavailable in Mac Catalyst Is Float16 - https://developer.apple.com/documentation/swift/float16 Apple Silicon only?
Posted
by Heestand.
Last updated
.
Post marked as solved
3 Replies
7.7k Views
I've updated my Swift Package, PixelKit, to Swift 5.3. I tagged my commit with 1.1.1 and pushed to origin. Tho when trying to add it to another package, it failed to resolve dependencies: because PixelKit >=1.0.13 contains incompatible tools version and root depends on PixelKit 1.1.1..<2.0.0, version solving failed. Here's how I include it: .package(url: "https://github.com/hexagons/PixelKit.git", from: "1.1.1") I'm not sure what the old tag 1.0.13 has to do with this. I'm using the same swift tools version in both packages: // swift-tools-version:5.3
Posted
by Heestand.
Last updated
.