我已经尝试过将屏幕外渲染WKWebView成图像
func cacheDisplayInRect(rect: NSRect, toBitmapImageRep bitmapImageRep: NSBitmapImageRep)func drawLayer(layer: CALayer, inContext ctx: CGContext)没有成功.生成的图像始终为空(白色或透明).有没有人设法在优胜美地上做到这一点?
我想运行一个可以监听OSX系统事件的守护进程,就像NSWorkspaceWillLaunchApplicationNotification在command line toolxcode项目中一样?那可能吗?如果没有,为什么不,有没有任何工作或黑客?
以下来自swift 2 cocoa application项目的示例代码设置了一个系统事件侦听器,WillLaunchApp每次启动OSX应用程序时都会调用该事件侦听器.(这很好用)
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
NSWorkspace.sharedWorkspace()
.notificationCenter.addObserver(self,
selector: "WillLaunchApp:",
name: NSWorkspaceWillLaunchApplicationNotification, object: nil)
}
func WillLaunchApp(notification: NSNotification!) {
print(notification)
}
}
Run Code Online (Sandbox Code Playgroud)
相比之下,这个类似的swift 2 command line tool项目不会打电话 WillLaunchApp.
import Cocoa
class MyObserver: NSObject
{
override init() {
super.init()
NSWorkspace.sharedWorkspace()
.notificationCenter.addObserver(self,
selector: "WillLaunchApp:",
name: NSWorkspaceWillLaunchApplicationNotification, object: nil)
}
func WillLaunchApp(notification: NSNotification!) { …Run Code Online (Sandbox Code Playgroud) 假设我想编写一个Star Field动画.不是通过使用OpenGL,而是直接绘制到屏幕缓冲区或可以放在屏幕上的屏幕外缓冲区.
在TRS-80上运行的Star Field演示当然只是一个例子.将视频解码或全屏动画视为需要每秒20+帧速率的其他可能性.
这样做的好方法是什么?我对官方和私有API实现都很感兴趣.
如果可以,请显示一些基本代码.
在http://mindbat.com/2013/03/clojurewest-2013-day-one-notes/上有一条说明如下:
我认为这是一个很好的建议,但我不完全确定如何在Ring/Compojure应用程序中实现它.任何人都可以举一个具体的例子说明这将如何运作?
我特别感兴趣的是如何组合defroutes,init并以app这种方式一起摆脱该范围内的全局变量.
以下是问题,如果类型是protocol.type,我无法调用类方法.是否有可以实现这一目标的替代模式.
真实情况是我有arr:[SomeProtocol.Type],我想执行let字符串:[String] = arr.map {$ 0.str}
protocol SomeProtocol: class {
static var str: String { get }
static func value() -> Int
}
class SomeClass: SomeProtocol {
static var str: String = "SomeClass"
static func value() -> Int {
return 1
}
}
let protocolType: SomeProtocol.Type = SomeClass.self
println(protocolType.str) // compile error
println(protocolType.value()) // compile error
Run Code Online (Sandbox Code Playgroud) 我正在快速教自己,我仍然很新,但我决定制作一个简单的应用程序,按下按钮打印当前时间.viewcontroller文件中的代码如下:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var LblTime: UILabel!
@IBAction func BtnCalltime(sender: AnyObject) {
var time = NSDate()
var formatter = NSDateFormatter()
formatter.dateFormat = "dd-MM"
var formatteddate = formatter.stringFromDate(time)
LblTime.text = time
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到了问题:
LblTime.text = time
Run Code Online (Sandbox Code Playgroud)
我一直收到错误:
无法将类型为"NSDate"的值分配给"String?"类型的值
我尝试过使用:
lblTime.text = time as! string?
Run Code Online (Sandbox Code Playgroud)
和:
lblTime.text = time as! string
Run Code Online (Sandbox Code Playgroud)
但它仍然不起作用,我会非常感谢一些帮助.谢谢
我正在考虑打电话net.IP.String(), strings.Split(ip, ".")一些代码来计算所有角落的情况,最后net.ParseIP(s).有更好的方法吗?下面是我当前实现的代码(没有处理特殊情况).
package main
import (
"fmt"
"net"
"strconv"
"strings"
)
func main() {
ip := net.ParseIP("127.1.0.0")
next, err := NextIP(ip)
if err != nil {
panic(err)
}
fmt.Println(ip, next)
}
func NextIP(ip net.IP) (net.IP, error) {
s := ip.String()
sa := strings.Split(s, ".")
i, err := strconv.Atoi(sa[2])
if err != nil {
return nil, err
}
i++
sa[3] = strconv.Itoa(i)
s = strings.Join(sa, ".")
return net.ParseIP(s), nil
}
Run Code Online (Sandbox Code Playgroud) 我需要在Go中切一个字符串.有时我有拉丁字符,否则我有阿拉伯语字符,但阿拉伯语的[:1]返回不同的值.
package main
import "fmt"
func main() {
a := "a"
fmt.Println(a[:1]) // work
b := "?"
fmt.Println(b[:1]) // not work
fmt.Println(b[:2]) // work
fmt.Println(len(a) == len(b)) // false
}
Run Code Online (Sandbox Code Playgroud)
我是iphone开发的新手,我一直在努力解决几天前发生的EXC_BAD_ACCESS错误.我基本上独立地使用斯坦福iphone类,我试图将一个NSManagedObjects数组传递给一个应该显示它们的TableViewController.应用程序在模拟器中启动并在tableView中显示数据,但它会立即出现EXC_BAD_ACCESS错误.
我按照这里和其他地方的说明如何使用NSZombieEnabled来识别过早释放的对象,但即使使用NSZombieEnabled也没有任何有用的消息.我的猜测是它必须是由于试图访问未通过发布/自动释放释放的未分配内存而导致的.否则它会被视为僵尸对象,就像我能够修复的其他错误一样.我不是专家,但如果我要声明一个对象并在没有实例化的情况下发送消息,那么这意味着会发生这样的事情吗?我查看了我的代码,看看我是否有类似的东西,我空了.
我在调试器中有堆栈跟踪,但我不知道如何使用它.我有点沮丧,因为我不能在代码中使用断点来进一步缩小问题,因为它似乎发生在应用程序加载完成后.如果没有可能的用户交互,我认为该应用程序将保持闲置状态.它是否在负载的尾端失败,我不能轻易看到它或者在完成加载后突然在后台做东西.我非常感谢有关如何阅读堆栈跟踪的任何提示.
我在下面键入了我的堆栈跟踪(无法弄清楚如何从调试器中复制它)
0 objc_msgSend
1 ??
2 -[NSManagedObject dealloc]
3 -[_PFManagedObjectReferenceQueue _processReferenceQue:]
4 _performRunLoopAction
5 ___CFRunLoopDoObservers
6 CFRunLoopRunSpecific
7 CFRunLoopRunInMode
8 GSEventRunModal
9 GSEventRun
10 UIApplicationMain
11 main
我的程序中的两个主要类是顶级委托类和它调用的ViewTableController.
` - (void)applicationDidFinishLaunching:(UIApplication*)application {
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
UINavigationController *contactsNavigationController = [[self createContactsNavigationController] retain];
//UINavigationController *recentsNavigationController = [[self createRecentsNavigationController:photos] retain];
tabBarController.viewControllers = [[NSArray alloc] initWithObjects: contactsNavigationController, nil];
[contactsNavigationController release];
//[recentsNavigationController release];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)
}
- (UINavigationController*)createContactsNavigationController {
UINavigationController *contactsNavigationController = [[UINavigationController alloc] init];
UITabBarItem *contactsTabBarItem …Run Code Online (Sandbox Code Playgroud) userid := 12345
did := (userid & ^(0xFFFF << 48))
Run Code Online (Sandbox Code Playgroud)
在编译这段代码时,我得到了:
./xxxx.go:511: constant -18446462598732840961 overflows int
你知道这件事有什么关系吗?如何解决?谢谢.
当我触摸按钮时,如何播放音频文件,没有什么工作可以在网上找到,因为它全部快速1.
我想要功能中的音频代码original.
import UIKit
import AVFoundation
class ViewController: UIViewController {
@IBAction func original(sender: AnyObject) {
}
}
Run Code Online (Sandbox Code Playgroud) 有没有人知道我怎么能告诉计时器在它达到0时停止.现在它继续倒数到零以下.
import UIKit
class ViewController: UIViewController {
var timerCount = 20
var timerRunning = false
var timer = NSTimer()
@IBOutlet weak var timerLabel: UILabel!
func Counting() {
timerCount -= 1
timerLabel.text = "\(timerCount)"
}
@IBAction func startButton(sender: UIButton) {
if timerRunning == false {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector ("Counting"), userInfo: nil, repeats: true)
timerRunning = true
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if …Run Code Online (Sandbox Code Playgroud)