我想隐藏最前面的应用程序.我知道你可以使用语法隐藏进程:
tell application "System Events"
set visible of process "..." to false
end tell
Run Code Online (Sandbox Code Playgroud)
我知道如何获得最前面的应用程序:
(path to frontmost application as string)
Run Code Online (Sandbox Code Playgroud)
但是,如何将两个命令连接在一起?
这不起作用:
tell application "System Events"
set visible of process (path to frontmost application as string) to false
end tell
Run Code Online (Sandbox Code Playgroud) 如何使用JavaScript插入两次HTML元素?
此代码无效:
var div = document.createElement('div');
div.innerText = 'Hello!';
document.body.appendChild(div);
document.body.appendChild(div);
Run Code Online (Sandbox Code Playgroud)
seconds
The number of seconds from the current date and time for the new date. Use a negative value to specify a date before the current date.
Run Code Online (Sandbox Code Playgroud)
但是,此代码在2148年给出了日期:
#import <Foundation/Foundation.h>
#import <stdlib.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
for(int i = 0; i < 30; i++) {
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval)-((u_int32_t)i * 12 * 60 * 60 + arc4random_uniform(8 * 60 * 60))];
NSLog(@"%@", date);
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它应该从近期生成半随机日期和时间.
为什么我不能用javascript重复一次CSS动画?
码:
static NSString* regexReplace(NSString* regexString, NSString* subject, NSString* replacement)
{
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexString options:0 error:nil];
return [regex stringByReplacingMatchesInString:subject options:0 range:NSMakeRange(0, [subject length]) withTemplate:replacement];
}
int main(int argc, const char * argv[])
{
@autoreleasepool
{
NSLog(@"%@", regexReplace(@".*", @"foo", @"bar")); //Output: barbar
NSLog(@"%@", regexReplace(@".+", @"foo", @"bar")); //Output: bar
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么".*"正则表达式将"foo"替换为"barbar"而不是"bar"?
错误:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<__NSDictionaryI 0x100110e00> valueForUndefinedKey:]:
this class is not key value coding-compliant for the key .'
Run Code Online (Sandbox Code Playgroud)
示例代码:
NSDictionary *dict = @{ @"foo": @"bar" };
NSLog(@"foo=%@, qaz=%@", [dict valueForKey:@"foo"], [dict valueForKey:@"qaz"]);
NSLog(@"@=%@", [dict valueForKey:@"@"]); // SIGABRT
Run Code Online (Sandbox Code Playgroud)
使用时也会发生这种情况[dict objectForKey:@"@"].
即使定义了"@"键,它仍会导致SIGABRT:
NSDictionary *dict = @{ @"@": @"at-sign" };
NSLog(@"@=%@", [dict valueForKey:@"@"]); // SIGABRT
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?如何从字典中检索"@"键的值?
我想做这样的事情:
"3*4".replace(/([0-9]+)[*]([0-9]+)/g, String(Number("$1") * Number("$2")))
Run Code Online (Sandbox Code Playgroud)
不,我不想那样做,而是更复杂的事情.
我想UINavigationBar在我的根视图中添加一个并在导航栏上设置标题.我尝试过使用其他类似问题的很多答案,但都没有奏效.
我正在以编程方式创建整个视图层次结构(因为我正在使用theos).在UINavagationBar启动应用程序时是可见的,但它没有标题,即使我都设置根视图控制器的标题和导航栏的标题顶部的项目.
我的应用程序只有一个主视图,因此导航栏仅出于美观原因.
该应用程序的完整源代码位于该行下方.
main.m文件:
int main(int argc, char **argv) {
@autoreleasepool {
return UIApplicationMain(argc, argv, @"CapabilitiesEditorApplication", @"CapabilitiesEditorApplication");
}
}
Run Code Online (Sandbox Code Playgroud)
CapabilitiesEditorApplication.m:
#import "RootViewController.h"
@interface CapabilitiesEditorApplication: UIApplication <UIApplicationDelegate> {
UIWindow *_window;
RootViewController *_viewController;
}
@property (nonatomic, retain) UIWindow *window;
@end
@implementation CapabilitiesEditorApplication
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_viewController = [[RootViewController alloc] init];
[_window addSubview:_viewController.view];
[_window makeKeyAndVisible];
}
@end
Run Code Online (Sandbox Code Playgroud)
RootViewController.h:
@interface RootViewController: UIViewController
@property UINavigationBar *navigationBar;
@end
Run Code Online (Sandbox Code Playgroud)
RootViewController.m: …
objective-c ×5
html ×2
ios ×2
regex ×2
applescript ×1
cgkeycode ×1
cocoa-touch ×1
css ×1
flash ×1
hide ×1
javascript ×1
macos ×1
nsdate ×1
pid ×1
process ×1