我知道有一个针对 InputMethodKit 框架的 API 参考。还有Objective-C 的示例代码,但没有提供 Swift 的示例。
有谁知道如何用 Swift 制作一个简单的 IME?它可以具有重复该字母但不执行任何操作等功能,因此我可以知道它确实有效。您使用哪些 Xcode SDK 构建并成功运行它?
这是我的测试代码(在终端中运行):
#!/usr/bin/xcrun swift
var count = 0; // for reference counting
class A {
init() {
count++;
}
deinit {
println("A deinit")
count--;
}
}
var a: A? = A()
println(count)
a = nil // no output if I comment out this statement
println(count)
Run Code Online (Sandbox Code Playgroud)
输出:
1
A deinit
0
Run Code Online (Sandbox Code Playgroud)
如果上面提到的行被注释掉,则没有输出"A deinit".输出将是:
1
1
Run Code Online (Sandbox Code Playgroud)
我曾经习惯swiftc编译代码但结果仍然相同.(xcrun swiftc -o test test.swift)
通过设计,当程序退出时,stdout将被关闭,或者当它们被破坏时,对象仍被引用(通过什么?)?
当它在函数内部运行时,A deinit即使我注释掉它也会输出a = nil:
#!/usr/bin/xcrun swift
class A {
deinit {
println("A …Run Code Online (Sandbox Code Playgroud)