Posts

Post marked as Apple Recommended
1.6k Views
I want to try the new TipKit features but when I import it from project, Xcode told me that No such module 'TipKit' and I also try the following code to create a tip directly but it doesn't work and Xcode shows Cannot find type 'Tip'. What can I do to use the new feature? // MARK: Tips define here. struct bookmarkTip: Tip { }
Posted Last updated
.
Post not yet marked as solved
0 Replies
372 Views
I create a simple app to enable user add an agenda to their calendar. I create an EventEditViewController which can be used in my SwiftUI app. When I tap the save button appeared on the sheet, the agenda can be saved to calendar but comes with some Xcode console output: redactedMimicSaveEvent: could not find corresponding remoteUI user committed permanent objectID for hostTempID[x-apple-eventkit:///Alarm/t6]. initialTempID[x-apple-eventkit:///Alarm/t5] What does that mean?
Posted Last updated
.
Post not yet marked as solved
0 Replies
696 Views
The following grammar is no longer available in Xcode 14, but the Store property is only available in macOS 12.0 +, my app also supports macOS 11.0, and now the compile is error, how can I solve this problem? struct PayButton: View {     @available(macOS 12.0, *)     @EnvironmentObject var store: Store ... }
Posted Last updated
.
Post not yet marked as solved
2 Replies
2k Views
Could anyone here tell me how I can use Live Text API in SwiftUI ? The code provide uses UIKit and not complete, the code is for existing project, but I want to develop a new SwiftUI project, so I have no idea how to implement it.
Posted Last updated
.
Post not yet marked as solved
0 Replies
1.1k Views
This is a macOS app, while using Image("my file url") in my CoverImageView, I can export a .png file that contains the Image("my file url") view successfully. However, this doesn't happen when I use Image(nsImage: NSImage(data: imageData.imagedata)), the imageData.imagedata is a Data type that will be gotten when I tap a button and get it from a selected picture (I will show it later in my code). When I select an image, it can be seen in my app's View. However, when I save this View(CoverImageView) to a .png file it only contain the blue view, the Mac view is gone!!!! Here is the CoverImageView from which I want to create a .png file struct CoverImageView: View { @EnvironmentObject var imageData: ImageData var body: some View { ZStack { Rectangle() .frame(width: 512, height: 600) .foregroundColor(.blue) Image(nsImage: (NSImage(data: imageData.imagedata) ?? NSImage(byReferencing: URL(fileURLWithPath: "")))) .resizable() .aspectRatio(contentMode: .fit) .frame(width: 512, height: 512) } } } This is the main view PhotoTestView struct PhotoTestView: View { @State private var imageUrl: URL = URL(fileURLWithPath: "") @EnvironmentObject var imageData: ImageData var body: some View { VStack { CoverImageView() Divider() .frame(width: 1024) HStack { Button(action: { if let openURL = ImageProcess().showOpenPanel() { imageUrl = openURL if let codedImages = try? Data(contentsOf: openURL) { imageData.imagedata = codedImages } } }, label: { Image(systemName: "doc.badge.plus") }) Button(action: { ImageProcess().saveImage() }, label: { Image(systemName: "square.and.arrow.down") }) }.padding() } } } The View Extension which will create a png file from a view extension View { func imageRepresentation(rect: CGRect) -> NSBitmapImageRep? { let hosting = NSHostingView(rootView: self) hosting.setFrameSize(rect.size) hosting.setBoundsSize(rect.size) hosting.layout() hosting.layerContentsRedrawPolicy = .onSetNeedsDisplay hosting.setNeedsDisplay(rect) if let imageRepresentation = hosting.bitmapImageRepForCachingDisplay(in: rect) { hosting.cacheDisplay(in: rect, to: imageRepresentation) return imageRepresentation } return nil } func asImage(rect: CGRect) -> NSImage? { if let cgImage = imageRepresentation(rect: rect)?.cgImage { return NSImage(cgImage: cgImage, size: rect.size) } return nil } func asPngData(rect: CGRect) -> Data? { return imageRepresentation(rect: rect)?.representation(using: .png, properties: [:]) } } png File Reader and Save struct ImageProcess { func showOpenPanel() -> URL? { let openPanel = NSOpenPanel() openPanel.allowedContentTypes = [.image] openPanel.allowsMultipleSelection = false openPanel.canChooseDirectories = false openPanel.canChooseFiles = true let response = openPanel.runModal() return response == .OK ? openPanel.url : nil } func saveURL() -> URL? { let savePanel = NSSavePanel() savePanel.allowedContentTypes = [.png] savePanel.canCreateDirectories = true savePanel.isExtensionHidden = false savePanel.allowsOtherFileTypes = false savePanel.title = "Save your image" savePanel.message = "Choose a folder and a name to store your image." savePanel.nameFieldLabel = "File name:" let response = savePanel.runModal() return response == .OK ? savePanel.url : nil } func saveImage() { let view = CoverImageView().environmentObject(ImageData()) let imageData = view.asPngData(rect: CGRect.init(x: 0, y: 0, width: 1024, height: 768)) if let url = saveURL() { try? imageData!.write(to: url) } // print(imageData) } } Could you help me?
Posted Last updated
.
Post not yet marked as solved
17 Replies
7.4k Views
In Xcode 11, Xcode shows some warnings of my project, how can I solve these warnings?The warnings shows like this:<unknown>:0: warning: imported declaration 'UITableViewDiffableDataSourceCellProvider' could not be mapped to 'UITableViewDiffableDataSourceReference.CellProvider'<unknown>:0: warning: imported declaration 'UICollectionViewDiffableDataSourceCellProvider' could not be mapped to 'UICollectionViewDiffableDataSourceReference.CellProvider'
Posted Last updated
.