How to print a NSRange in NSLog
Asked Answered
A

2

26

Say my range is created as

NSRange myRange = {0,100};

How do I print myRange in NSLog? The following is not working

NSLog(@"my range is %@",myRange);
Alan answered 8/8, 2014 at 21:53 Comment(0)
M
56

Use NSStringFromRange.

NSLog(@"my range is %@", NSStringFromRange(myRange));

In Swift you can do:

print("my range is \(NSStringFromRange(myRange))")
Monson answered 8/8, 2014 at 21:55 Comment(2)
Is NSStringFromRange(myRange) the proper way to do it in Swift?Jus
OK. Thank you. :-)Jus
S
7

Use NSStringFromRange(myRange).

Stuccowork answered 8/8, 2014 at 21:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.