LoginSignup
7
6

More than 5 years have passed since last update.

iOS SimulatorでiOS8を動かすとEUC-JPエンコードのバイト列をNSStringにするときにエラーとなる

Last updated at Posted at 2014-09-26

Summary

タイトルの通りなんですがEUC-JPエンコードのバイト列をNSStringにするときに以下のエラーが発生します。
iOS SimulatorをiOS7で動かすと正しく読み込めます。(Xcode6.0, Xcode6.1で確認)

Error Domain=NSCocoaErrorDomain Code=261 "The operation couldn’t be completed. (Cocoa error 261.)" UserInfo=0x7fdfe2657ef0 {NSFilePath=/Users/tetsuo/Library/Developer/CoreSimulator/Devices/766F5633-A7C6-45AE-AADF-A2182FA157EF/data/Containers/Bundle/Application/7DC78A9D-4BA7-44D2-9852-AC6A099014FE/TestApp3.app/eucdata.txt, NSStringEncoding=3}

Description

Xcodeでプロジェクトを適当につくって、以下のようなコードを書いて検証しました。
(Swiftで書くのは初めてなので、慣れないな...)

    @IBAction func actionHoge(sender: UIButton) {
        if let dataPath = NSBundle.mainBundle().pathForResource("eucdata", ofType: "txt") {
            var error : NSError?
            let str = NSString(contentsOfFile: dataPath, encoding: NSJapaneseEUCStringEncoding, error: &error)

            if let e = error {
                NSLog("%@", e)
            } else {
                NSLog("str: %@", str)
            }
        }
    }

ちょっと試した感じだと回避方法が見つからなかったので、Appleにお願いだな...

7
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6