-2

My code calls String.appendingFormat to append a formatted string to a value that is used as output in an iPhone app. When the call includes the format string and two value arguments (e.g. ("The numbers are %d and %d", number1, number2)), it works fine on the simulator, but on my iPad, the second value is always treated as zero.

Note that, in each case, the value comes from a Int64 array.

Why would it work differently on an actual device than in the simulator?

Here's a better-formatted version of my reply (one of these days, I'm going to remember that newlines get swallowed in replies):

var results = [Int64]()
var A: Int64 = 123
results.append(A) 

On the simulator, results[0] = 123

On the iPad, results[0] = what looks like a pointer; it's an 11-digit number that changes each time the code is executed

var outputString: String = ""
outputString = outputString.appendingFormat("%d %d", A, results[0]) 

On the simulator, outputString = "123 123"

On the iPad, outputString = "123 0"

Don Del Grande
  • 411
  • 6
  • 20
  • 5
    Need your code to debug. – Santosh Oct 12 '16 at 01:44
  • 1
    http://stackoverflow.com/a/8679/642626 – Bryan Chen Oct 12 '16 at 01:46
  • 1
    print like this. `print("The numbers are \(number1) and \(number2)")` – Rajan Maheshwari Oct 12 '16 at 02:54
  • Here's the quick version: `var results = [Int64](); var A: Int64 = 123; results.append(A)` On the simulator, results[0] = 123 On the iPad, results[0] = what looks like a pointer; it's an 11-digit number that changes each time the code is executed `var outputString: String = ""; outputString = outputString.appendingFormat("%d %d", A, results[0])` On the simulator, outputString = "10 123" On the iPad, outputString = "10 0" – Don Del Grande Oct 12 '16 at 04:51
  • sorry don't get it .. where is the 10 from now and where is the 11 digit number and .. :D sorry – Daij-Djan Oct 12 '16 at 13:12
  • Good catch - both of the 10s should be 123 (originally, I had A = 10, but changed it to 123 to make it a little easier to read) – Don Del Grande Oct 12 '16 at 15:44
  • How are you getting the output string? Can you show us your print line? – Chris Allwein Oct 12 '16 at 15:59
  • I'm getting correct results on iOS10 on a 6Plus. "print(outputString) print("The numbers are \(A) and \(results[0])")" is giving me "123 123 The numbers are 123 and 123" – Chris Allwein Oct 12 '16 at 16:09

1 Answers1

0

Turns out Bryan Chen's link was the solution - what was happening was, since I was using %d instead of %lld, every Int64 was being displayed as its four low bytes in decimal, followed by its four high bytes. When I added additional arguments to the call, it would show the first argument, then zero, then the second argument, then zero, and so on.

Don Del Grande
  • 411
  • 6
  • 20