Swiftで遊ぼう! on Hatena

あしたさぬきblogでやってた初心者オヤジのiOSプログラミング奮闘記がHatenaに来ました

Swiftで遊ぼう! - 660 - UIGestureRecognizerState.Changedの実装に進む

次のTable Viewのチュートリアルを拡張しています。

yataiblue.hatenablog.com

本当にゆっくりです。ゆっくりでも続けていればアプリができるという事を早く皆さんに見せたいですね。仕事の傍らに勉強を続けているんで焦らず頑張ります。

やっと UIGestureRecognizerState.Changedの条件を考えます。

case UIGestureRecognizerState.Changed:
   var center = MyCell.cellSnapshot!.center
   center.y = locationInView.y
   MyCell.cellSnapshot!.center = center
   if ((indexPath != nil) && (indexPath != MyCell.initialIndexPath)) {
       swap(&items[indexPath!.row], 
                  &items[MyCell.initialIndexPath!.row])
       simpleTableView.moveRowAtIndexPath(MyCell.initialIndexPath!, 
                                           toIndexPath: indexPath!)
       MyCell.initialIndexPath = indexPath
   }

このコードはチュートリアルで紹介されているコードですが...

やっぱり疑問に思う部分があります...

「var center = MyCell.cellSnapshot!.center」は必要なのでしょうか?

かなり助長に見えてしまうのですが、理由があるのでしょうか? 私なら次のようにします。

case UIGestureRecognizerState.Changed:
   MyCell.cellSnapshot!.center = locationInView.y
   if ((indexPath != nil) && (indexPath != MyCell.initialIndexPath)) {
       swap(&items[indexPath!.row], 
                  &items[MyCell.initialIndexPath!.row])
       simpleTableView.moveRowAtIndexPath(MyCell.initialIndexPath!, 
                                           toIndexPath: indexPath!)
       MyCell.initialIndexPath = indexPath
   }

ベテランプログラマーの皆さん、助言をお願いしますm(_ _)m

ちょっと短いですが今日はこれだけ。