我在Xcode 8中将我的(macOS)项目转换为Swift 3,并且我使用swift类中实现的几个委托方法得到以下警告:
Instance method 'someMethod' nearly matches optional requirement of protocol 'protocolName'
Run Code Online (Sandbox Code Playgroud)
我得到这个好NSApplicationDelegate方法,如applicationDidFinishLaunching和applicationDidBecomeActive:
但也适用于tableViewSelectionDidChange:

我使用代码完成来插入方法签名,并尝试从SDK标头中复制它们以排除拼写错误.警告不会消失,并且永远不会调用这些方法.
我在这里错过了什么?
我需要在类中包含从公共框架头中排除的属性,但它可以在其他框架类中内部使用.我现在做的是:
MyClass.h:
@interface MyClass: NSObject
@end
Run Code Online (Sandbox Code Playgroud)
MyClass的+ Internal.h
@interface MyClass (Internal)
@property (nonatomic, copy) NSString *mySecretProperty;
@end
Run Code Online (Sandbox Code Playgroud)
MyClass.m
#import "MyClass.h"
#import "MyClass+Internal.h"
@interface MyClass ()
@property (nonatomic, copy) NSString *mySecretProperty;
@end
@implementation MyClass
@end
Run Code Online (Sandbox Code Playgroud)
我可以使用私人财产,如:
MyOtherClass.m:
#import "MyClass.h"
#import "MyClass+Internal.h"
@implementation MyOtherClass
- (void)test {
MyClass *myClass = [MyClass new];
NSLog(@"%@", myClass.mySecretProperty)
}
@end
Run Code Online (Sandbox Code Playgroud)
但我不喜欢这个设置是我在我的Internal类别和匿名类别中有重复的属性声明.有没有办法改善这种设置?
更新到 Xcode 10 后,我意识到draw(_ rect: CGRect)我的应用程序中自定义 UIView(从 UIView 派生的类)的例程被调用了错误的rect. 事实上,它总是以rect底层 UIView 的完整框架被调用,而不是rect由setNeedsDisplay(_ rect: CGRect).
这是一个可以作为游乐场运行的代码片段,至少在我的设置中,它显示了上面在简约设置中描述的错误行为:
import Foundation
import UIKit
import PlaygroundSupport
class CustomView: UIView {
override func draw(_ rect: CGRect) {
print("rect = \(rect)")
}
}
let customView = CustomView(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: 200.0, height: 200.0)))
PlaygroundPage.current.liveView = customView
print("test")
customView.setNeedsDisplay(CGRect(origin: CGPoint.zero, size: CGSize(width: 100.0, height: 100.0)))
Run Code Online (Sandbox Code Playgroud)
我得到的输出是
rect = (0.0, 0.0, 200.0, 200.0)
测试
rect = (0.0, 0.0, …