我是OCMock的新用户,所以也许我只是在这里错过了一些简单的东西.此代码无法编译:
id mockSession = [OCMockObject mockForClass:[AVCaptureSession class]];
[[mockSession expect] addOutput:[OCMArg anyPointer]];
Run Code Online (Sandbox Code Playgroud)
错误是
Multiple methods named 'addOutput:' found with mismatched result, parameter type or attributes
Run Code Online (Sandbox Code Playgroud)
AVCaptureSession上方法addOutput的签名如下
- (void)addOutput:(AVCaptureOutput *)output
Run Code Online (Sandbox Code Playgroud)
据我所知,问题是方法addOutput存在于AVCaptureSession和AVAssetReader类中.AVAssetReader上addOutput的方法签名如下.
- (void)addOutput:(AVAssetReaderOutput *)output
Run Code Online (Sandbox Code Playgroud)
显然编译器认为我的mockSession是一个AVAssetReader,但我不知道为什么它选择该类而不是AVCaptureSession.如果我期望AVCaptureSession上的另一种方法在AVAssetReader上不存在,那么它就会编译.我试过以下没有成功.它编译,但崩溃.
id mockSession = [OCMockObject mockForClass:[AVCaptureSession class]];
[(AVCaptureSession*)[mockSession expect] addOutput:[OCMArg anyPointer]];
Run Code Online (Sandbox Code Playgroud)
此代码也不编译,与前一个错误相同
id mockSession = [OCMockObject mockForClass:[AVCaptureSession class]];
AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[[mockSession expect] addOutput:output];
Run Code Online (Sandbox Code Playgroud)
这里的任何指导?
我无法找到如何key:true在我的NSDictionary中插入一个布尔值(在JSON字符串中显示):
NSMutableDictionary* jsonDict = [NSMutableDictionary dictionary];
[jsonDict setValue: YES forKey: @"key"];
Run Code Online (Sandbox Code Playgroud)
上面的代码没有运行(显然因为YES不是对象).
我怎么能做到这一点?
我花了整个下午的时间撞到墙上,试图弄清楚为什么这门课的解码失败了.该类有一个属性,它是Foo对象的NSArray.Foo符合NSSecureCoding,我已成功编码并解码了该类.我在initWithCoder中收到错误:表示无法解码类Foo.通过一些实验,我发现我需要将[Foo类]添加到initWithCoder:为了使它工作.也许这会帮助那些遇到同样问题的人.我的问题是,为什么这是必要的?我没有发现在Apple的文档中这是必要的.
#import "Foo.h"
@interface MyClass : NSObject <NSSecureCoding>
@property (nonatomic) NSArray *bunchOfFoos;
@end
@implementation MyClass
static NSString *kKeyFoo = @"kKeyFoo";
+ (BOOL) supportsSecureCoding
{
return YES;
}
- (void) encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:self.bunchOfFoos forKey:kKeyFoo];
}
- (id) initWithCoder:(NSCoder *)decoder
{
if (self = [super init])
{
[Foo class]; // Without this, decoding fails
_bunchOfFoos = [decoder decodeObjectOfClass:[NSArray class] forKey:kKeyFoo];
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud) 我有一个视图,以编程方式创建子视图并为其添加一些约束.出于某种原因,约束被完全忽略.不会抛出任何错误.约束根本不起作用.子视图与超级视图具有相同的框架.我期待它是400x400并以其超级视图为中心.我在这做错了什么?这是我在superview中的initWithFrame:
- (id) initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
instructionsView = [[UIView alloc] initWithFrame:frame];
[self addSubview:instructionsView];
[self bringSubviewToFront:instructionsView];
[self addConstraint:[NSLayoutConstraint constraintWithItem:instructionsView
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterX
multiplier:1.
constant:0]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:instructionsView
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.
constant:0]];
[instructionsView addConstraint:[NSLayoutConstraint constraintWithItem:instructionsView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.
constant:400]];
[instructionsView addConstraint:[NSLayoutConstraint constraintWithItem:instructionsView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.
constant:400]];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
我试过改变
instructionsView = [[UIView alloc] initWithFrame:frame];
Run Code Online (Sandbox Code Playgroud)
至
instructionsView = [[UIView alloc] initWithFrame:CGRectZero];
Run Code Online (Sandbox Code Playgroud)
没有成功.
我的基于 Win32 的桌面应用程序中有一个 WinRT 类(C++/CX 引用类)。它访问 WinRT API 并且工作得很好。我使用本指南来让它工作。现在我试图将此类放入桌面应用程序可以使用的库中。我在这方面遇到了一些麻烦。这是我在 Visual Studio 2013 中所做的:
#using <MyLib.winmd>
#using <Windows.winmd>
#using <Platform.winmd>
[MTAThread] // initializes WinRT runtime
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow) {
MyWinRTClass^ myObject = ref new MyWinRTClass();
}
Run Code Online (Sandbox Code Playgroud)
智能感知可以工作,我编写了代码来实例化库中的类。桌面应用程序已构建,但当它运行时我得到:
MyDesktopApp.exe 中 0x76494598 处的首次机会异常:Microsoft C++ 异常:Platform::ClassNotRegisteredException ^ …
我在图层委托中有以下代码.它只是绘制一个蓝色圆圈.它在32位iOS设备上运行完美,但在64位iOS设备上没有任何效果.为什么?
-(void) drawLayer:(CALayer *)layer inContext:(CGContextRef)context
{
CGContextAddArc(context, 100., 100., 10., -M_PI, M_PI, YES);
CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);
CGContextFillPath(context);
}
Run Code Online (Sandbox Code Playgroud) objective-c ×5
ios ×4
autolayout ×1
c++-cx ×1
cocoa ×1
dll ×1
drawing ×1
json ×1
macos ×1
nsarray ×1
nscoding ×1
ocmock ×1
unit-testing ×1
windows-8 ×1