Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ReactiveCocoaで日本語入力

 ReactiveCocoaで日本語入力

iOSのカスタムキーボードでReactiveCocoaを利用して日本語入力を試みた内容です。

Jiro Nagashima

January 15, 2015
Tweet

More Decks by Jiro Nagashima

Other Decks in Technology

Transcript

  1. Ωʔೖྗ RACSignal *signal = [self rac_signalForSelector:@selector(buttonDidTouchUp:)]; return [[[signal reduceEach:^(KeyboardButton *button){

    return button; }] filter:^BOOL(KeyboardButton *button) { return button.keyIndex < KeyboardButtonIndexShift; }] map:^(KeyboardButton *button) { NSString *inputCharacter = [button titleForState:UIControlStateNormal]; return inputCharacter; }];  ΞϧϑΝϕοτͷ 4USFBN 4JHOBM ˞3"$$PNNBOEͰ΋Մ I P O O
  2. I P O O RACSignal *vowelSignal = [[inputSignal filter:^BOOL(NSString *inputCharacter)

    { return [@[@"A", @"I", @"U", @"E", @"O"] containsObject:inputCharacter]; }] map:^(id _) { NSMutableString *mutableBuffer; mutableBuffer = [NSMutableString stringWithString:self.buffer]; CFStringTransform((CFMutableStringRef)mutableBuffer, NULL, kCFStringTransformLatinHiragana, FALSE); return [NSString stringWithString:mutableBuffer]; }]; ฼Ի ͷ 4USFBN ม׵ Τϯδϯ   ͻΒ͕ͳ ͷ 4USFBN ΄ ΞϧϑΝϕοτ ͷ 4USFBN
  3. ࿈ଓจࣈ ͷ 4USFBN   ͻΒ͕ͳ ͷ 4USFBN ΞϧϑΝϕοτ ͷ

    4USFBN I P O O RACSignal *consecutiveSignal = [[[bufferedInputConnection.signal combinePreviousWithStart:@"" reduce:^(NSString *previous, NSString *current) { return [NSSet setWithArray:@[previous, current]]; }] filter:^BOOL(NSSet *characters) { return [characters count] == 1; }] map:^(NSSet *characters) { NSString *consecutiveCharacter = [characters anyObject]; return ([consecutiveCharacter isEqualToString:@"N"]) ? @"Μ" : @"ͬ"; }]; ม׵ Τϯδϯ Μ
  4. ʷ ͻΒ͕ͳ ͷ 4USFBN  ͻΒ͕ͳ ͷ 4USFBN RACSubject *transformedCharacter

    = [RACSubject subject]; [[[RACSignal merge:@[vowelSignal, consecutiveSignal]] doNext:^(id _) { self.buffer = [[NSMutableString alloc] init]; }] subscribe:transformedCharacter]; ม׵ Τϯδϯ ΄ ม׵ Τϯδϯ Μ ΄ Μ