title: How ObjectiveC mutableCopy work in swift
body: <p>I am new in Swift and iOS development in general. Recently I was trying to use Swift to write an iOS app that uses CorePlot (which is written in ObjectiveC). I tried to rewrite a CorePlot iOS sample code (found in <a href="http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2" rel="nofollow">http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2</a>) in Swift. There is a line like this in the sample objectiveC:</p>
  
  <pre><code>CPTMutableLineStyle *aaplLineStyle = [aaplPlot.dataLineStyle mutableCopy];
  aaplLineStyle.lineWidth = 2.5;
  </code></pre>
  
  <p>that I tried to rewrite like this:</p>
  
  <pre><code>var lineStyle = aaplPlot.dataLineStyle.mutableCopy();
  lineStyle.lineColor = aaplColor;
  </code></pre>
  
  <p>The problem is I get a compile error in my Swift version of code saying </p>
  
  <pre><code>"cannot assign to 'lineColor' in 'lineStyle'". 
  </code></pre>
  
  <p>I also got a warning saying that </p>
  
  <pre><code>"variable lineStyle inferred to have type 'AnyObject', which may be unexpected"
  </code></pre>
  
  <p><strong><code>'applePlot'</code></strong>, by the way, is of type CPTLineStyle defined like this in ObjectiveC:</p>
  
  <pre><code>@interface CPTLineStyle : NSObject&lt;NSCoding, NSCopying, NSMutableCopying&gt;
  
  @property (nonatomic, readonly) CGLineCap lineCap;
  @property (nonatomic, readonly) CGLineJoin lineJoin;
  @property (nonatomic, readonly) CGFloat miterLimit;
  @property (nonatomic, readonly) CGFloat lineWidth;
  @property (nonatomic, readonly) NSArray *dashPattern;
  @property (nonatomic, readonly) CGFloat patternPhase;
  @property (nonatomic, readonly) CPTColor *lineColor;
  @property (nonatomic, readonly) CPTFill *lineFill;
  @property (nonatomic, readonly) CPTGradient *lineGradient;
  @property (nonatomic, readonly, getter = isOpaque) BOOL opaque;
  
  /// @name Factory Methods
  /// @{
  +(instancetype)lineStyle;
  /// @}
  
  /// @name Drawing
  /// @{
  -(void)setLineStyleInContext:(CGContextRef)context;
  -(void)strokePathInContext:(CGContextRef)context;
  -(void)strokeRect:(CGRect)rect inContext:(CGContextRef)context;
  /// @}
  
  @end
  </code></pre>
  
  <p>Can any body tell me if I was doing something wrong? How do I rewrite that lines of code in swift correctly?</p>
  
  <p>Thanks</p>