本文介绍了迅速1.2覆盖NSManagedObject扩展中的prepareForDeletion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Swift 1.2中覆盖函数 prepareForDeletion 失败

Overriding the function prepareForDeletion fails in swift 1.2

// Playground - noun: a place where people can play

import UIKit
import CoreData

extension NSManagedObject {
    @objc func prepareForDeletion() {
        println("deleting object")
    }
}
@objc func prepareForDeletion() {
           ^
@objc func prepareForDeletion()

有人有主意吗?

谢谢罗恩

推荐答案

不能覆盖同一类扩展中的类中的方法,这样做始终是未定义的行为.

You cannot override a method in a class in an extension of the same class, doing so was always undefined behaviour.

对于在Swift中覆盖Objective-C方法,在此未引起注意Xcode 6.2,现在可以在Xcode 6.3 beta中正确诊断.

For overriding Objective-C methods in Swift this went unnoticed inXcode 6.2 and is now properly diagnosed in Xcode 6.3 beta.

请注意,Objective-C中的相应做法–同一类的Objective-C扩展中的重写方法–也不允许,请参阅避免类别方法名称冲突" :

Note that the corresponding practice in Objective-C – overriding methods in an Objective-C extension of the same class – is also not allowed, see "Avoid Category Method Name Clashes":

您可以做的是在您的自定义方法中覆盖该方法 NSManagedObject 子类.

What you can do is to to override the method in your customNSManagedObject subclasses.

这篇关于迅速1.2覆盖NSManagedObject扩展中的prepareForDeletion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 23:31