NSTextTab - Proper Use of "Options"

I recently started using Xcode 7 and got what seems like a general warning:

Null passed to a callee that requires a non-null argument 

I understand what is telling me, but I'm not sure if the solution is right for my specific problem. Here is the line where the warning occurs:

 NSTextTab *tab = [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentLeft location:10.0f options:nil]; 

Now that I’ve looked at Matt Neuberg’s example in his book iOS 8 Programming (published 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 the text so that the decimal points in the lines match. Excellent. Useful Not what I need. I'm just trying to have a tab on the left side, giving a specific and consistent indent.

To β€œfix” my code (that is, make the warning disappear), I changed my code to this:

 NSTextTab *tab = [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentLeft location:10.0f options:[NSDictionary dictionary]]; 

It seems to work, but it looks like a super-kludgy work-around. Is my understanding of NSTextTab wrong? What is the right way to fix this?

+5
source share
1 answer

The only option mentioned in the documentation for initWithTextAlignment: location: options: is NSTabColumnTerminatorsAttributeName, and this is optional.

Parameters: The parameter is marked non-zero in the NSParagraphStyle.h header file using the NS_ASSUME_NONNULL_BEGIN / END macros.

Combine these two facts, and your decision to pass an empty NSDictionary is the right way to resolve the compiler warning.

+3
source

All Articles