我的目标是能够获得文件/文件夹和密码,使用Objective-C在AES中对其进行加密和解密.我不是加密书呆子或任何东西,但我之所以选择AES是因为我发现它非常标准并且非常安全.我使用的是NSMutableData类,它有加密和解密数据的方法.这里是:
- (NSInteger)AES256EncryptionWithKey: (NSString*)key {
// The key should be 32 bytes for AES256, will be null-padded otherwise
char keyPtr[kCCKeySizeAES256 + 1]; // room for terminator (unused)
bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
// Fetch key data
if (![key getCString: keyPtr maxLength: sizeof(keyPtr) encoding: NSUTF8StringEncoding])
{ return 2; } // Length of 'key' is bigger than keyPtr
NSUInteger dataLength = [self length];
// See the doc: For block ciphers, the output size will always be less than or …Run Code Online (Sandbox Code Playgroud) 有没有办法知道一个元素是否在html页面上可见?
像这样:

人们可以考虑水平/垂直滚动位置,浏览器窗口的宽度/高度以及页面上元素的位置/大小,但我对jQuery的经验很少,所以我不知道怎么做.可能会有一个简单的功能,我不知道.
我有一个基于视图的NSTableView与自定义NSTableCellView和自定义NSTableRowView.我自定义了这两个类,因为我想改变每一行的外观.通过实现[NSTableRowView draw ...]方法,我可以更改背景,选择,分隔符和拖动目标高亮显示.
我的问题是:如何更改右键单击行并出现菜单时出现的突出显示?
例如,这是常态:

我想将方形高光改为圆形,如下所示:

我想这可以通过调用drawMenuHighlightInRect:或类似的方法在NSTableRowView中完成,但我找不到它.另外,如果我在我的子类中定制了所有绘图方法,并且我不调用超类,那么NSTableRowView类如何才能这样做呢?这是由表本身绘制的吗?
经过一些实验,我发现可以通过将tableview设置为源列表来实现圆形突出显示.尽管如此,我想知道如何在可能的情况下自定义它.
我一直试图用最近的NSUserScriptTask类及其子类来做(看到这个和这个),到目前为止我已经解决了一些问题,但还有一些问题仍有待解决.从文档中可以看出,NSUserScriptTask不允许取消任务.因此,我决定创建一个简单的可执行文件,将脚本的路径作为参数并运行脚本.这样,我可以使用NSTask从我的主应用程序启动帮助程序,并[task terminate]在必要时调用.但是,我要求:
主应用程序的代码很简单:只需使用正确的信息启动NSTask即可.这就是我现在所拥有的(为了简单起见,我忽略了安全范围的书签之类的代码,这些代码都没有问题.但是不要忘记这是运行沙盒的):
// Create task
task = [NSTask new];
[task setLaunchPath: [[NSBundle mainBundle] pathForResource: @"ScriptHelper" ofType: @""]];
[task setArguments: [NSArray arrayWithObjects: scriptPath, nil]];
// Create error pipe
NSPipe* errorPipe = [NSPipe new];
[task setStandardError: errorPipe];
// Create output pipe
NSPipe* outputPipe = [NSPipe new];
[task setStandardOutput: outputPipe];
// Set termination handler
[task setTerminationHandler: ^(NSTask* task){
// Save output
NSFileHandle* outFile = [outputPipe fileHandleForReading];
NSString* output = [[NSString alloc] initWithData: …Run Code Online (Sandbox Code Playgroud) 小牛队即将面市,对于那些一直忙于开发所有这些新功能和API来了解和使用的开发人员来说.对我而言,我认为现在是提出一个长期困扰我的问题的最佳时机.
这是事情,在上下文中:我正在开发一个我希望能够在10.8上运行的应用程序(因此目标系统是10.8+).现在我正在使用10.8 SDK.但是,随着10.9的发布,我想在我的应用程序中使用一些非常好的API.我在我的代码中使用它们,但当然,我必须针对10.9 SDK编译我的应用程序.如果我这样做,我还可以在10.8上运行应用程序吗?
或者,以更一般的方式,如果我针对一个SDK编译我的应用程序,我是否仍然可以在"较低"的Mac OS上运行它?如果是,你能解释一下它是如何工作的(编译器在做什么)?这对我来说是个谜.
我以前有这个代码使用QTKit从Mac的iSight摄像头捕获单个图像:
- (NSError*)takePicture
{
BOOL success;
NSError* error;
captureSession = [QTCaptureSession new];
QTCaptureDevice* device = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo];
success = [device open: &error];
if (!success) { return error; }
QTCaptureDeviceInput* captureDeviceInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
success = [captureSession addInput: captureDeviceInput error: &error];
if (!success) { return error; }
QTCaptureDecompressedVideoOutput* captureVideoOutput = [QTCaptureDecompressedVideoOutput new];
[captureVideoOutput setDelegate: self];
success = [captureSession addOutput: captureVideoOutput error: &error];
if (!success) { return error; }
[captureSession startRunning];
return nil;
}
- (void)captureOutput: (QTCaptureOutput*)captureOutput
didOutputVideoFrame: (CVImageBufferRef)imageBuffer …Run Code Online (Sandbox Code Playgroud) kIOPMAssertionTypeNoIdleSleep,kIOPMAssertionTypePreventSystemSleep和有什么区别kIOPMAssertionTypePreventUserIdleSystemSleep?
我正在尝试创建一个IOPMAssertion可以防止 mac 自动进入睡眠状态的程序,但我真的不知道应该使用哪一个。我对他们的描述感到困惑,无法理解它们(请参阅文档)。
如果您好奇,这就是我在代码中执行此操作的方式:
IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR("My app is running"), &preventSleepAssertionID);
if (success != kIOReturnSuccess) {
NSLog(@"Could not create sleep prevention assertion");
}
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来在滚动内容时在桌面视图(和大纲视图,但我认为它将是相同的)上绘制淡入淡出效果.以下是Fantastical应用程序的示例:

此处还有QuickLook窗口上类似淡入淡出的视频.
为此,我尝试使用以下代码子类化tableview的scrollview:
#define kFadeEffectHeight 15
@implementation FadingScrollView
- (void)drawRect: (NSRect)dirtyRect
{
[super drawRect: dirtyRect];
NSGradient* g = [[NSGradient alloc] initWithStartingColor: [NSColor blackColor] endingColor: [NSColor clearColor]];
NSRect topRect = self.bounds;
topRect.origin.y = self.bounds.size.height - kFadeEffectHeight;
topRect.size.height = kFadeEffectHeight;
NSRect botRect = self.bounds;
botRect.size.height = kFadeEffectHeight;
[NSGraphicsContext saveGraphicsState];
[[NSGraphicsContext currentContext] setCompositingOperation: NSCompositeDestinationAtop];
// Tried every compositing operation and none worked. Please specify wich one I should use if you do it this way
[g drawInRect: topRect angle: 90]; …Run Code Online (Sandbox Code Playgroud) 我有一个想要设置动画的 NSView,但是该 NSView 有一个 NSTableView,当视图是图层支持时,该 NSTableView 不会显示正确性(这又是动画视图所必需的)。所以我的答案是在动画之前让视图图层支持,然后当动画完成时删除图层,如下所示:
[animatingView setWantsLayer: YES];
[NSAnimationContext beginGrouping];
[[animatingView animator] animateSomething];
[[NSAnimationContext currentContext] setCompletionHandler: ^{
[animatingView setWantsLayer: NO];
}];
[NSAnimationContext endGrouping];
Run Code Online (Sandbox Code Playgroud)
但是,使用此代码,视图根本不会产生动画。我发现,如果删除该[animatingView setWantsLayer: NO];线,它的动画效果会恰到好处,但表视图无法正确显示(请参阅此问题以获取其中一个问题的示例)。
所以,我的问题是:我该如何解决这个问题?我想要为视图设置动画,但我希望表格能够正确显示,但此解决方法不起作用。而且我不明白为什么...
我有多个函数返回一个std::optional<T>. 下面是一个虚构类型的例子MyType:
struct MyType {
// ...
}
std::optional<MyType> calculateOptional() {
// ... lengthy calculation
if (success) {
return MyType(/* etc */);
}
return std::nullopt;
}
Run Code Online (Sandbox Code Playgroud)
让我们假设这些函数的运行成本很高,我想避免多次调用它们。
调用它们时,我想立即测试可选项,如果它确实包含一个值,我想立即使用它,永远不要再使用它。例如,在 Swift 中,我可以使用标准if-let语句:
if let result = calculateOptional() {
// Use result var
}
Run Code Online (Sandbox Code Playgroud)
我想在 C++ 中复制这种测试和解包行为,同时在使用时尽可能保持代码干净。例如,显而易见的简单解决方案(至少对我而言)是:
if (auto result = calculateOptional()) {
MyType result_unwrapped = *result;
// Use result_unwrapped var
}
Run Code Online (Sandbox Code Playgroud)
但是您必须在 . 中解包if,或者*result在任何地方使用,这与 Swift 无关。
到目前为止,我唯一真正接近 Swift 的外观和感觉的解决方案是:
template<typename T> bool …Run Code Online (Sandbox Code Playgroud) objective-c ×7
cocoa ×5
macos ×3
nstableview ×3
aes ×1
avfoundation ×1
browser ×1
c++ ×1
c++17 ×1
contextmenu ×1
fade ×1
highlight ×1
iokit ×1
javascript ×1
jquery ×1
nsscrollview ×1
nstask ×1
sdk ×1
security ×1
stdoptional ×1