Skip to content

AlasKuNull/mecab-ios-sample

 
 

Repository files navigation

MeCab Sample App for iOS

Sample Swift project for MeCab, a Japanese tokenizer/morphological analyzer. Updated for iOS 12.x and Swift 5.

Use the following command to clone and get the mecab-ios submodule as well:

git clone --recurse-submodules https://github.com/landonepps/mecab-ios-sample.git

Setting up your own project

  1. Create a new Xcode Swift project and make it a git repository (or let Xcode do it for you).

  2. Add mecab-ios as a submodule by executing the following command in your project's repository:

git submodule add https://github.com/landonepps/mecab-ios.git
  1. Select Add Files to "ProjectName"... from the Xcode menu and choose mecab.xcodeproj in the mecab-ios folder created by adding the submodule. This will import the project and all the necessary files.

  2. Drag mecabrc from the top directory of this repository into your project. Make sure to select Copy items if needed.

  3. Open the mecab-ios folder in your project's folder and drag the ipadic folder into your project. (The files are already in your project's directory. so it doesn't matter if you have Copy items if needed selected or not.)

  4. Click on your project file, go to the target's General tab, and add mecab.framework in the Embedded Binaries section near the bottom.

  5. Make sure to import mecab wherever you need to use it.

  6. You can now call the MeCab library's functions directly from Swift – e.g.

let mecab = mecab_new2("-d \(Bundle.main.resourcePath!)")
  1. Dealing with MeCab directly is not ideal, so feel free to use the Swift wrappers that I made for this sample project: Tokenizer.swift and Token.swift.

  2. Clean and build.

These instrucations are based on the ones from https://github.com/lxmmxl56/iPhone-libmecab

Special thanks to Joseph Toronto on Stack Overflow for coming up with the original steps.

About

Sample Swift 5 project for MeCab on iOS 10.3 to 12.x

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Swift 100.0%