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
		guard error == nil else { return }
		guard let image: MPImage = reading as? MPImage else { return }
		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?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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.
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?
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.
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?
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:
<plist version="1.0">
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>File Name</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.mysite.file</string>
</array>
<key>LSTypeIsPackage</key>
<true/>
</dict>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UISupportsDocumentBrowser</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>com.apple.package</string>
<string>public.composite-content</string>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>File Name</string>
<key>UTTypeIdentifier</key>
<string>com.mysite.file</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>myext</string>
</array>
</dict>
</dict>
</array>
</dict>
</plist>
Does anyone know how to debug this?
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