Holding onto a struct

How can I hang onto the following struct outside of the method it is created? I've been trying to assign it to a instance variable or property without much luck.

@property(nonatomic) CTParagraphStyleSetting defaultParagraphSettings;

- (void)someMethod {
    CTParagraphStyleSetting settings[] = {
        { kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment },
        { kCTParagraphStyleSpecifierLineBreakMode, sizeof(CTLineBreakMode), &lineBreakMode },
    };
    self.defaultParagraphSettings = settings;
}

self.defaultParagraphSettings = settings; generates the following error:

Assigning to 'CTParagraphStyleSetting' (aka 'struct CTParagraphStyleSetting') from incompatible type 'CTParagraphStyleSetting [4]'

Am I going about this the right way?

Answers


The error message is telling you that the variable settings is of type array of CTParagraphStyleSetting, the property defaultParagraphSettings is of type CTParagraphStyleSetting. So you have two problems, (1) the types are incompatible and (2) (Objective-)C does not support array assignment.

I can't tell you how to fix it as that depends on what you're trying to do. But for example, the statement:

self.defaultParagraphSettings = settings[0];

should assign the first element of the array to the property.


Need Your Help

XNA graphicsdevice.present crashes on “value does not fall within the expected range”

graphics error-handling xna

I have an XNA application, that when run on a certain laptop (dell, Win 7 64bit) will crash.

Can we instantiate an abstract class? Is it possible?

java abstract

I read in SCJP6 that an abstract class cannot be instantiated. But read somewhere that they can be instantiated. Is is true?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.