title: Difference when converting method from Objective-C to Swift
body: <p>This is my method in Objective-C:</p>
  
  <pre><code>- (CATransform3D)carousel:(iCarousel *)carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform
  {
      //items in the center are scaled by this factor
      const CGFloat centerScale = 5.0f;
      //the larger the xFactor, the smaller the magnified area
      const CGFloat xFactor = 0.65f;
      //should the gap also be scaled? or keep it constant.
      const BOOL scaleGap = NO;
  
      const CGFloat spacing = [self carousel:carousel valueForOption:iCarouselOptionSpacing withDefault:1.025];
  
      const CGFloat gap = scaleGap?0.0:spacing-1.0;
  
      //counting x offset to keep a constant gap
      CGFloat scaleOffset = 0.0;
      float x = fabs(offset);
      for(;x &gt;= 0.0; x-=1.0)
      {
          scaleOffset+=[self scaleForX:x xFactor:xFactor centerScale:centerScale];
          scaleOffset+= ((x&gt;=1.0)?gap:x*gap);
      }
      scaleOffset -= [self scaleForX:offset xFactor:xFactor centerScale:centerScale]/2.0;
      scaleOffset += (x+0.5)*[self scaleForX:(x+(x&gt;-0.5?0.0:1.0)) xFactor:xFactor centerScale:centerScale];
      scaleOffset *= offset&lt;0.0?-1.0:1.0;
      scaleOffset *= scaleGap?spacing:1.0;
  
      CGFloat scale = [self scaleForX:offset xFactor:xFactor centerScale:centerScale];
      transform = CATransform3DTranslate(transform, scaleOffset*carousel.itemWidth, 0.0, 0.0);
      transform = CATransform3DScale(transform, scale, scale, 1.0);
      return transform;
  }
  </code></pre>
  
  <p>This is how it looks:</p>
  
  <p><img src="https://i.stack.imgur.com/5iNwF.png" alt="enter image description here"></p>
  
  <p>This is how I changed it to Swift:</p>
  
  <pre><code>func carousel(carousel: iCarousel!, itemTransformForOffset offset: CGFloat, baseTransform transform: CATransform3D) -&gt; CATransform3D
  {
      let centerScale : CGFloat = 5.0
      let xFactor : CGFloat = 0.65
      let scaleGap : Bool = false
      let spacing : CGFloat = self.carousel(carousel, valueForOption: iCarouselOption.Spacing, withDefault: 1.025)
      let gap : CGFloat = scaleGap ? 0 : spacing - 1.0
      var scaleOffset : CGFloat = 0.0
      var x : CGFloat = fabs(offset)
      for (;x &gt;= 0.0 ; x -= 1.0)
      {
          scaleOffset += NumberScroller.scaleForX(x, xFactor: xFactor, centerScale: centerScale)
          scaleOffset += ((x &gt;= 1.0) ? gap : x * gap)
      }
  
      scaleOffset -= NumberScroller.scaleForX(offset, xFactor: xFactor, centerScale: centerScale)
      scaleOffset += (x + 0.5) * NumberScroller.scaleForX((x + ( x &gt; -0.5 ? 0.0 : 1.0 )), xFactor: xFactor, centerScale: centerScale)
      scaleOffset *= offset &lt; 0.0 ? -1.0 : 1.0
      scaleOffset *= scaleGap ? spacing : 1.0
  
      var scale : CGFloat = NumberScroller.scaleForX(offset, xFactor: xFactor, centerScale: centerScale)
      var newTransform : CATransform3D = transform
      newTransform = CATransform3DTranslate(transform, scale, scale, 1.0)
      newTransform = CATransform3DScale(transform, scale, scale, 1.0)
      return newTransform;
  }
  </code></pre>
  
  <p>This is how it looks:</p>
  
  <p><img src="https://i.stack.imgur.com/3VJ8U.png" alt="enter image description here"></p>