I have recently begun using Xcode 7 and have gotten what appears to be a common warning:
Null passed to a callee that requires a non-null argument
I understand what it is telling me, but I am not sure what the correct solution is for my particular issue. Here's the line where the warning is occurring:
NSTextTab *tab = [[NSTextTab alloc]
initWithTextAlignment:NSTextAlignmentLeft
location:10.0f
options:nil];
Now, looking into Matt Neuberg's example of this in his "Programming iOS 8" book (posted on GitHub), I see the following:
let s = "Onions\t$2.34\nPeppers\t$15.2\n"
let mas = NSMutableAttributedString(string:s, attributes:[
// lines omitted...
let terms = NSTextTab.columnTerminatorsForLocale(NSLocale.currentLocale())
let tab = NSTextTab(textAlignment:.Right, location:170, options:[NSTabColumnTerminatorsAttributeName:terms])
// lines omitted
self.tv.attributedText = mas
From what I can tell, this is setting up the text so that the decimal points in the strings are what get aligned. Great. Useful. Not what I need. I'm just trying to have a tab on the left-hand side give a specific and consistent indentation.
To "fix" my code (i.e., get the warning to disappear), I've changed my code to this:
NSTextTab *tab = [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentLeft location:10.0f options:[NSDictionary dictionary]];
This appears to work, but it feels like a super-kludgy work-around. Is my understanding of NSTextTab
mistaken? What's the right way to fix this?
The only option listed in the documentation for initWithTextAlignment:location:options: is NSTabColumnTerminatorsAttributeName and it is optional.
The options: parameter is marked nonnull in the NSParagraphStyle.h header file by the use of the NS_ASSUME_NONNULL_BEGIN/END macros.
Combine those two facts, and your solution of passing an empty NSDictionary is the proper way to resolve the compiler warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With