LoginSignup
38
37

More than 5 years have passed since last update.

swift3.0での変更点(一部)

Posted at

swift3.0がリリースされ、変更が入った箇所のうち、
よく使いそうなところをメモしました。

「CGRectMake」→「CGRect」

<変更前>

swift
private let mylabel = UILabel(frame:CGRectMake(0, 0, 100, 100))

<変更後>

swift
private let mylabel = UILabel(frame:CGRect(x: 0, y: 0, width: 100, height: 100))

「CGSizeMake」→「CGSize」

<変更前>

swift
myScrollview.contentSize = CGSizeMake(100, 100)

<変更後>

swift
myScrollview.contentSize = CGSize(width: 100, height: 100)

UIColor

<変更前>

swift
myScrollview.backgroundColor = UIColor.clearColor()

<変更後>

swift
myScrollview.backgroundColor = UIColor.clear

フォントのサイズ指定

<変更前>

swift
mylabel.font = UIFont.boldSystemFontOfSize(18)

<変更後>

swift
mylabel.font = UIFont.boldSystemFont(ofSize: 18)

bringSubview

<変更前>

swift
self.view.bringSubviewToFront(mylabel)

<変更後>

swift
self.view.bringSubview(toFront: mylabel)

openURL、NSURL

<変更前>

swift
let otherAction = UIAlertAction(title: "はい", style: .Default) {
    action in
    UIApplication.sharedApplication().openURL(NSURL(string: "tel://119")!)
}

<変更後>

swift
let otherAction = UIAlertAction(title: "はい", style: .default) {
    action in
    UIApplication.shared.openURL(URL(string: "tel://119")!)
}

<変更前>

swift
let myURL = NSURL(string:myAppURL)

<変更後>

swift
let myURL = URL(string:myAppURL)

「NSDate」→「Date」

「NSCalendar」→「Calendar」

「NSDateComponents」→「DateComponents」

<変更前>

swift
self.view.bringSubviewToFront(mylabel)

<変更後>

swift
self.view.bringSubview(toFront: mylabel)

「dismissViewControllerAnimated」→「dismiss」

<変更前>

swift
dismissViewControllerAnimated(true, completion: nil)

<変更後>

swift
dismiss(animated: true, completion: nil)

「popViewControllerAnimated」→「popViewController」

<変更前>

swift
self.navigationController?.popViewControllerAnimated(true)

<変更後>

swift
self.navigationController?.popViewController(animated: true)

「rangeOfString」→「range」

<変更前>

swift
let loc = itemsSearchText[i].rangeOfString(sMySearchBar!).location

<変更後>

swift
let loc = itemsSearchText[i].range(of: sMySearchBar!).location

「NSDateFormatter」→「DateFormatter」

<変更前>

swift
let myDateFormatter: NSDateFormatter = NSDateFormatter()

<変更後>

swift
let myDateFormatter: DateFormatter = DateFormatter()

NSTimeZone

<変更前>

swift
myDatePicker.timeZone = NSTimeZone.localTimeZone()

<変更後>

swift
myDatePicker.timeZone = TimeZone.autoupdatingCurrent
38
37
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
37