Accessing a static variable and setting it outside the class
<p>Here is a SubtitleCustomField class.</p><pre><br /><code>Class SubtitleCustomField: CustomCellField {<br />static var CellIdentifier: String!<br /><br /> override init(frame: CGRect) {<br /> super.init(frame: frame)<br /> if CellIdentifier == "A" {<br /> //DO SOMETHINIG<br /> } else if CellIdentifier == "B" {<br /> //DO SOMETHING<br /> }<br /><br /> }<br />}<br /></code><br /></pre><p>Outside SubtitleCustomField class, I basically need to access static variable CellIdentifier, set value like "A", and trigger if statement to run.</p><p>In another class, Custom class, I've confirmed that I can access the static variable, Cell Identifier, in a following way:</p><pre><br /><code>Class Custom: CustomViewController {<br /> SubtitleCustomField.CellIdentifier = "part1_subtitle"<br />}<br /></code><br /></pre><p>I face a problem at this point. In SubtitleCustomField class, I get an error on <code>if CellIdentifier == "A"</code> saying</p><blockquote><p>Static member 'CellIdentifier' cannot be used on instance of type 'SubtitleCustomField'</p></blockquote><p>What would be the best approach I can use to achieve what I want? In summary, I want to set CellIdentifier variable outside <code>'SubtitleCustomField'</code> and trigger if statement with the value I set in <code>'SubtitleCustomField'</code> class.</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34524967/accessing-a-static-variable-and-setting-it-outside-the-class">http://ift.tt/1PwiBi9</a></h2>
Nhận xét
Đăng nhận xét