I also have tried to convert Apple's IMKit sample first part "NumberInput 0" project from Objective-c to Swift
If "NumberInput 0" in Swift project works, then following NumberInput 1,2,3 can be converted quickly.
"NumberInput 0" in Swift project can be compiled, installed, added to input sources, can be be selected and ran, but the IMKInputController subclass NumberInputController's method inputText(...) can't be reached by typing keys when I using Xcode to debug NumberInput.app
NumberInput 0 is simply only includes 4 files, few lines of code:
- AppDelegate.swift
- NumberInputController.swift
- MainMenu.xib
- Info.plist
NumberInputController is listed in info.plist.
I have successfully recreated "NumberInput 0" project using Objective-C with Xcode 7, all works, NumberInputController function inputText(...) can be reached by typing keys when debugging.
I am new to Swift, can any one help me to get "NumberInput 0" in Swift working?
Following are contents of 3 files:
AppDelegate.swift
import Cocoa
import InputMethodKit
let kConnectionName = "NumberInput_1_Connection"
var server:IMKServer = IMKServer.init()
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
let identifier = NSBundle.mainBundle().bundleIdentifier;
server = IMKServer.init(name: kConnectionName, bundleIdentifier: identifier)
}
func applicationWillTerminate(aNotification: NSNotification) {
}
}
NumberInputController.swift
import Cocoa
import InputMethodKit
class NumberInputController: IMKInputController {
override func inputText(string:String, client: AnyObject) ->Bool {
// Debug break point put here
print(string);
return false;
}
}
Info.plist
...
<dict>
....
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSBackgroundOnly</key>
<string>1</string>
<key>InputMethodConnectionName</key>
<string>NumberInput_1_Connection</string>
<key>InputMethodServerControllerClass</key>
<string>NumberInputController</string>
<key>tsInputMethodIconFileKey</key>
<string>nine.tiff</string>
<key>tsInputMethodCharacterRepertoireKey</key>
<array>
<string>Latn</string>
</array>
</dict>
</plist>
Thanks.