プロトタイプへの呼び出しが認識できないセレクタで失敗しても、コード自体がアプリケーション自体で正常に動作するという奇妙な問題があります。誰もが、なぜこれが起こっているのか知っていますか?ここで私が働いているものがあります。Objective-CプロトコルがXCTestでセレクタに失敗しましたが、アプリケーションに含まれていません
MKPolygon + PointInPolygon.h
@import Foundation;
@import MapKit;
@interface MKPolygon (PointInPolygon)
- (BOOL)containsCoordinate:(CLLocationCoordinate2D)coordinate;
@end
MKPolygon + PointInPolygon.m
#import "MKPolygon+PointInPolygon.h"
@implementation MKPolygon (PointInPolygon)
- (BOOL)containsCoordinate:(CLLocationCoordinate2D)coordinate
{
MKMapPoint mapPoint = MKMapPointForCoordinate(coordinate);
MKPolygonRenderer *polygonView = [[MKPolygonRenderer alloc] initWithPolygon:self];
CGPoint polygonViewPoint = [polygonView pointForMapPoint:mapPoint];
BOOL returnResult = CGPathContainsPoint(polygonView.path, NULL, polygonViewPoint, NO);
return returnResult;
}
@end
MKPolygon + PointInPolygonTests.m
#import <XCTest/XCTest.h>
#import "MKPolygon+PointInPolygon.h"
@interface MKPolygon_PointInPolygonTests : XCTestCase
@end
@implementation MKPolygon_PointInPolygonTests
- (void)testThatCoordinateIsNotInPolygon {
//Canton
CLLocationCoordinate2D outsidePolygonLocation = CLLocationCoordinate2DMake(40.798946, -81.378448);
//Columbus Bounds
CLLocationCoordinate2D nw = CLLocationCoordinate2DMake(40.0, -83.0);
CLLocationCoordinate2D ne = CLLocationCoordinate2DMake(40.0, -82.0);
CLLocationCoordinate2D se = CLLocationCoordinate2DMake(39.0, -82.0);
CLLocationCoordinate2D sw = CLLocationCoordinate2DMake(39.0, -83.0);
CLLocationCoordinate2D coords[] = {nw, ne, se, sw};
MKPolygon *polygon = [MKPolygon polygonWithCoordinates:coords count:4];
BOOL result = [polygon containsCoordinate:outsidePolygonLocation];
XCTAssertFalse(result);
}
[ポリゴンcontainsCoordinate:outsidePolygonLocation]の呼び出しの原因認識できないセレクタエラー
上記のテストメソッドコードをアプリケーションにコピーすると、XCTAssertionには---正常に動作します。
私は何が起こっているのか迷っています。私は他の人にこれを見せてもらったが、間違ったことは見ない。
テストバンドルが 'MKPolygon + PointInPolygon.m'ファイルでコンパイルされていません。 Xcodeでそのファイルのターゲットのリストを確認し、テストターゲットが含まれていることを確認してください。 – hamstergene
それはそれでした。私はプロトコルの実装ファイルをテストターゲットに追加していませんでした。 –
また、[プロトコル](https://///////////// /developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/Protocols.html#//apple_ref/doc/uid/TP40011210-CH11-SW1)を参照してください。彼らは同じではありません!カテゴリは既存のクラスを拡張します。プロトコルとは、特定のタスクまたはタスクセットを実行するために実装する必要があるクラス(多くの場合、作成しているもの)です。 – user1118321