我正在尝试填充NSObject自定义类的数组,但是当我插入数据时收到错误:[Wood_Factory___Gerenciador.FotoProduto setFoto:]: unrecognized selector sent to instance 0x6080000055a0
调用类
的操作@IBAction func selecionarFotosButtonClicked(_ sender: NSButton) {
let panel = NSOpenPanel()
panel.canChooseFiles = true
panel.canChooseDirectories = false
panel.allowsMultipleSelection = true
panel.canCreateDirectories = false
panel.allowedFileTypes = NSImage.imageTypes
panel.beginSheetModal(for: view.window!) { (result) in
if result.rawValue == NSFileHandlingPanelOKButton {
for url in panel.urls {
let fotoNSImage = NSImage(byReferencing: url)
let fotoNSImageRedim = Ferramentas.redimensionaNSImage(imagem: fotoNSImage, tamanho: NSSize(width: 200, height: 200))
let fotoNSImageRep = NSBitmapImageRep(data: (fotoNSImageRedim.tiffRepresentation)!)
let fotoNSImagePng = fotoNSImageRep?.representation(using: NSBitmapImageRep.FileType.png, properties: [:])
//let fotoProduto = FotoProduto(foto: PFFile(data: fotoNSImagePng!)!, categorias: [])
let fotoProduto = FotoProduto()
fotoProduto.foto = PFFile(data: fotoNSImagePng!)
fotoProduto.categorias = []
fotoProduto.imagemCapa = false
self.projeto?.fotos = [FotoProduto]()
self.projeto?.fotos.append(fotoProduto)
}
self.verificaCapaDefinida()
if !self.capaDefinida {
let indiceImagem = IndexPath(item: 0, section: 0)
self.definirImagemCapa(indice: indiceImagem, limparSelecao: true)
} else {
self.fotosProjetoCollectionView.deselectAll(self)
self.fotosProjetoCollectionView.reloadData()
}
}
}
}
FotoProduto Class
import Cocoa
import Parse
class FotoProduto: NSObject {
@NSManaged var foto: PFFile?
@NSManaged var categorias: [String]
@NSManaged var imagemCapa: Bool
override init() {
super.init()
}
}
以下是完整错误:
2017-09-21 07:13:58.074278-0400木材厂 - Gerenciador [1241:101761] - [Wood_Factory ___ Gerenciador.FotoProduto setFoto:]:无法识别的选择器发送到实例0x6080000055a0 2017-09-21 07:13:58.478223-0400木材厂 - Gerenciador [1241:101761] [一般] - [Wood_Factory ___ Gerenciador.FotoProduto setFoto:]:无法识别的选择器发送到实例0x6080000055a0 2017-09-21 07:13:58.482745-0400木工厂 - Gerenciador [1241:101761] [一般] (0 CoreFoundation 0x00007fff930452cb exceptionPreprocess + 171 1 libobjc.A.dylib 0x00007fffa7e5d48d objc_exception_throw + 48 2 CoreFoundation
0x00007fff930c6f04 - [NSObject(NSObject)doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x00007fff92fb7755 ___ forwarding _ + 1061 4 CoreFoundation 0x00007fff92fb72a8 _CF_forwarding_prep_0 + 120 5 Wood Factory - Gerenciador 0x000000010003e68c _T026Wood_Factory___Gerenciador30GerenciarProjetoViewControllerC28selecionarFotosButtonClickedySo8NSButtonCFySo13NSApplicationC13ModalResponseVcfU_ + 1948 6 Wood Factory - Gerenciador 0x000000010003ee78 _T026Wood_Factory___Gerenciador30GerenciarProjetoViewControllerC28selecionarFotosButtonClickedySo8NSButtonCFySo13NSApplicationC13ModalResponseVcfU_TA + 88 7 Wood Factory - Gerenciador 0x000000010000ba01 _T0So13NSApplicationC13ModalResponseVIxy_ADIyBy_TR + 49 8 AppKit 0x00007fff911b78b9 - [NSSavePanel _didEndSheet:returnCode:contextInfo:] + 95 9 AppKit 0x00007fff90d25b84 - [NSWindow _endWindowBlockingModalSession:returnCode:] + 308 10 AppKit 0x00007fff911ba073 - [NSSavePanel ok:] + 461 11 libsystem_trace.dylib 0x00007fffa89753a7 _os_activity_initiate_impl + 53 12 AppKit 0x00007fff91232721 - [NSApplication(NSResponder)sendAction:to:from:] + 456 13 AppKit 0x00007fff90d16cc4 - [NSControl sendAction:to:] + 86 14 AppKit 0x00007fff90d16bec __26- [NSCell _sendActionFrom:] _ block_invoke + 136 15 libsystem_trace.dylib 0x00007fffa89753a7 _os_activity_initiate_impl + 53 16 AppKit 0x00007fff90d16b44 - [NSCell _sendActionFrom:] + 128 17 AppKit
0x00007fff90d59539 - [NSButtonCell _sendActionFrom:] + 98 18 libsystem_trace.dylib 0x00007fffa89753a7 _os_activity_initiate_impl + 53 19 AppKit 0x00007fff90d15426 - [NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2481 20 AppKit 0x00007fff90d59272 - [NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 798 21 AppKit 0x00007fff90d13ddb - [NSControl mouseDown:] + 832 22 AppKit
0x00007fff913ae24f - [NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 6341 23 AppKit 0x00007fff913aaa6c - [NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 1942 24 AppKit 0x00007fff913a9f0a - [NSWindow(NSEventRouting)sendEvent:] + 541 25 AppKit 0x00007fff9122e681 - [NSApplication(NSEvent)sendEvent:] + 1145 26 AppKit 0x00007fff90aa9427 - [NSApplication run] + 1002 27 AppKit
0x00007fff90a73e0e NSApplicationMain + 1237 28 Wood Factory - Gerenciador 0x000000010005038d main + 13 29 libdyld.dylib
0x00007fffa8743235 start + 1)
答案 0 :(得分:0)
解决方案是创建PFObject的子类。
import Cocoa
import Parse
class FotoProduto: PFObject, PFSubclassing {
@NSManaged var foto: PFFile?
@NSManaged var categorias: [String]
@NSManaged var imagemCapa: Bool
override init() {
super.init()
}
init(foto: PFFile, categorias: [String]) {
super.init()
self.foto = foto
self.categorias = categorias
self.imagemCapa = false
}
static func parseClassName() -> String {
return "FotoProduto"
}
}