【Swift】Xcode 8 & Swift 3 対応時の変更メモ

現在少しずつXcode 8&Swift 3の対応を行なっています
その時に対応したときのメモです

他にもあればどんどん追記していこうと思います

//info.plistに必要なPrivacyを追加
Privacy – Camera Usage Description
Privacy – Photo Library Usage Description
// 多言語対応の場合は、各言語のInfoPlist.stringsに追加
NSCameraUsageDescription = “Take a photo”;
NSPhotoLibraryUsageDescription = “Save a photo”;

//--- Before ---//
image.drawInRect(rect)
//--- After ---//
image.draw(in: rect)
//--- Before ---//
UIViewAnimationOptions.CurveEaseOut
//--- After ---//
UIViewAnimationOptions.curveEaseOut
//--- Before ---//
UIGestureRecognizerState.Began
UIGestureRecognizerState.Changed
UIGestureRecognizerState.Ended
//--- After ---//
UIGestureRecognizerState.began
UIGestureRecognizerState.changed
UIGestureRecognizerState.ended
//--- Before ---//
imageView.contentMode = UIViewContentMode.ScaleAspectFit
//--- After ---//
imageView.contentMode = UIViewContentMode.scaleAspectFit
//--- Before ---//
imageView.userInteractionEnabled = true
//--- After ---//
imageView.isUserInteractionEnabled = true
//--- Before ---//
CGPointZero
//--- After ---//
CGPoint.zero
//--- Before ---//
cardView.transform = CGAffineTransformIdentity
//--- After ---//
cardView.transform = CGAffineTransform.identity
//--- Before ---//
let delay = 1.0 * Double(NSEC_PER_SEC)
var time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue(), {
    //処理
})

//--- After ---//
let dispatchTime: DispatchTime = DispatchTime.now() + Double(Int64(1.0 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
    DispatchQueue.main.asyncAfter(deadline: dispatchTime, execute: {
    //処理
})
//--- Before ---//
CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y)

//--- After ---//
context?.addQuadCurve(to: CGPoint(x: mid2.x, y: mid2.y), control:CGPoint(x: previousPoint1.x, y: previousPoint1.y) )
//--- Before ---//
for var i = 1; i <= extraCount; i += 1 {
}

//--- After ---//
for i in 1 ... extraCount {
}
//--- Before ---//
//@IBOutlet weak var myWebView: UIWebView!
myWebView.load(data!, mimeType: "text/html", textEncodingName: "utf-8", baseURL: URL())

//--- After ---//
myWebView.load(data!, mimeType: "text/html", textEncodingName: "utf-8", baseURL: URL(string: "/")!)
//--- Before ---//
CGContextEOFillPath(context)

//--- After ---//
context?.fillPath(using: CGPathFillRule.winding)
// または
context?.fillPath(using: CGPathFillRule.evenOdd)
//--- Before ---//
let request = NSFetchRequest()

//--- After ---//
let request: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest()
//--- Before ---//
let results: NSArray! = try managedObjectContext.fetch(request)

//--- After ---//
let ret = try managedObjectContext.fetch(request)
let results = NSArray(array: ret)    
//--- Before ---//
CGPathMoveToPoint(curvedPath, nil, startPos.x, startPos.y)

//--- After ---//
curvedPath.move(to: CGPoint(x: startPos.x, y: startPos.y))
//--- Before ---//
CGPathAddCurveToPoint(curvedPath, nil,
            startPos.x, startPos.y - height,
            targetPos.x, startPos.y - height,
            targetPos.x, targetPos.y)

//--- After ---//
curvedPath.addCurve(to: CGPoint(x: startPos.x, y: startPos.y - height),
                            control1: CGPoint(x: targetPos.x, y: startPos.y - height),
                            control2: CGPoint(x: targetPos.x, y: targetPos.y))
//--- Before ---//
UIView.beginAnimations("flip", context: nil)
//〜
UIView.commitAnimations()

override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
}

//--- After ---//
UIView.beginAnimations("flip", context: nil)
//〜
UIView.setAnimationDelegate(self) 
UIView.commitAnimations()

func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
}

//--- Before ---//
CGContextAddArcToPoint(context, rect.minX, rect.minY, rect.midX, rect.minY, r)

//--- After ---//
context?.addArc(tangent1End: CGPoint(x: rect.minX, y: rect.minY), tangent2End: CGPoint(x: rect.midX, y: rect.minY), radius: r)
//--- Before ---//
self.navigationController?.popViewController(animated: true)

//--- After ---//
let _ = self.navigationController?.popViewController(animated: true)
//--- Before ---//
DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.default).async(execute: {
})

//--- After ---//
DispatchQueue.global().async(execute: {
})
関連コンテンツ
ブログランキング
  • にほんブログ村 教育ブログ プログラミング教育へ
  • にほんブログ村 子育てブログ 子供の習い事(教室・業者)へ

  • スポンサーリンク
    Google336 記事下
    Google336 記事下

    シェアする

    • このエントリーをはてなブックマークに追加

    フォローする

    スポンサーリンク
    Google336 記事下
    トップへ戻る