0

I am storing level details inside of a text file within my iOS project. The Text File contains the following:

Level1.txt

    LevelNum:1.0
    weaponPickupRate:10.0
    weaponPickupAmount:20
    monsterMinSpeed:8.0
    monsterMaxSpeed:12.0
    monsterRate:1.5
    levelMonsters:10
    goldPerMonster:10

I am reading the text file using the code below:

    fileName = "Level1.txt"
    levelPath = "\(NSBundle.mainBundle().resourcePath!)/\(fileName)"

    var err: NSError? = NSError()
    let s = String(contentsOfFile: levelPath, encoding: NSUTF8StringEncoding, error: &err)

    println(s)

When I run this using the iOS Simulator - iPhone 6, everything works fine and it prints the data from the text file.

When I run this directly on my iPhone 6 it prints nil and does not read the text file.

Why is this?

Cheers Ryann

Ryann786
  • 289
  • 4
  • 12
  • Dump out the file path and then use Xcode Organizer to check if it's really there. – Hot Licks Feb 11 '15 at 23:53
  • try using this instead and see what it retuns `levelPath = NSBundle.mainBundle().pathForResource("Level1", ofType: "txt")` – rakeshbs Feb 12 '15 at 01:29

0 Answers0