2017-09-21 5 views
0

を設定するときに認識されていないセレクタが、私はNSObjectのカスタムクラスの配列を移入しようとしていますが、私はデータを挿入するとき、私はエラーが表示さNSObjectのサブクラスのインスタンスに送信される:クラススウィフトOSX - 値

を呼び出し [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クラス

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 Wood Factory - Gerenciador[1241:101761] -[Wood_Factory___Gerenciador.FotoProduto setFoto:]: unrecognized selector sent to instance 0x6080000055a0 2017-09-21 07:13:58.478223-0400 Wood Factory - Gerenciador[1241:101761] [General] -[Wood_Factory___Gerenciador.FotoProduto setFoto:]: unrecognized selector sent to instance 0x6080000055a0 2017-09-21 07:13:58.482745-0400 Wood Factory - Gerenciador[1241:101761] [General] ( 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

CoreDataを使用していますか? – Larme

+0

いいえ、私はCoreDataを使用していません – GuiDupas

+1

NSManagedObject(CoreData用)では '@ NSManaged'はありませんか? – Larme

答えて

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" 
    } 
}