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

ReactiveCocoaで日本語入力

 ReactiveCocoaで日本語入力

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

03c0e11ea6f2a3e08b3c46db5877c8e1?s=128

Jiro Nagashima

January 15, 2015
Tweet

Transcript

  1. 3FBDUJWF$PDPB Ͱ ೔ຊޠೖྗ !IFEKJSPH

  2. ͳ͕͠·͡Ζ͏ !IFEKJSPH 4BOTBOגࣜձࣾ&JHIU

  3. ΍Γ͍ͨ͜ͱ

  4. 3FBDUJWF$PDPB ϦΞΫςΟϒϓϩάϥϛϯά

  5. ʓ4USFBN ʷ.77. ʷCJOEJOH ࿩͢͜ͱ

  6. ʲ຋༁ʳ͋ͳ͕ͨٻΊ͍ͯͨϦΞΫςΟϒϓϩάϥϛϯάೖ໳ Θ͔Γ΍͍͢ʂʂ

  7. ೔ຊޠೖྗ

  8. Ωʔೖྗ

  9. I P O O ΞϧϑΝϕοτ

  10. ม׵ Τϯδϯ

  11. ΄ Μ ͻΒ͕ͳ

  12. ೔ຊޠೖྗ ͻΒ͕ͳม׵ Ωʔೖྗ ΞϧϑΝϕοτ ͻΒ͕ͳ

  13. ೔ຊޠೖྗ ͻΒ͕ͳม׵ Ωʔೖྗ ΞϧϑΝϕοτ ͻΒ͕ͳ 4USFBN 4USFBN 3FBDUJWF$PDPB

  14. ΍ͬͨ͜ͱ

  15. IFEKJSPH3FBDUJWF,FZCPBSE

  16. IFEKJSPH3FBDUJWF,FZCPBSE ˣˣˣGPSLˣˣˣ LJTIJLBXBLBUTVNJ +BQBOFTF,FZCPBSE,JU

  17. Ωʔೖྗ 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
  18. 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
  19. ࿈ଓจࣈ ͷ 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"]) ? @"Μ" : @"ͬ"; }]; ม׵ Τϯδϯ Μ
  20. ʷ ͻΒ͕ͳ ͷ 4USFBN  ͻΒ͕ͳ ͷ 4USFBN RACSubject *transformedCharacter

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

  22. 049༻ͷ4,,"RVB4,, ϝϯςφϯεऴྃʂʂ

  23. DPEFpSTUBRVBTLL ༗ࢤʹΑΔमਖ਼൛഑෍΋͋Δ͕ʜ

  24. ʘઈࢍ։ൃதʂʂʗ 4USFBN4,, Ծ