3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

New features in Swift 3.0

Last updated at Posted at 2016-04-12

#####Document:Apple Swift Document

#####Release Notes:Official release notes

import UIKit

class ViewController: UIViewController
{

    override func viewDidLoad()
    {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        // 修改1:traditional C-style for loop is deprecated
        for i in 0..<3
        {
            print(i)
        }
        
        // ps. for var i = 3; i > 0; i-- {} can be write like blow:
        for i in (0..<3).reverse()
        {
            print(i)
        }
        
        // ps. for var i = 0; i < 10; i+=2 {} can be write like blow:
        for i in 0.stride(to: 10, by: 2)
        {
            print(i)
        }
        
        // 修改2: selector will be checked in compile-time
        let tap = UITapGestureRecognizer(target: self, action: #selector(selectorFunc))
        view.addGestureRecognizer(tap)
        
        // 修改3: Swift version-check will be in compile-time
        #if swift(>=2.2)
            print("Swift 2.2+")
        #else
        	 This code will never be checked!!!!!!!!
            print("Swift 2.2-")
        #endif
        
        // 修改4:
        testFunc("kuang", age: 25)
        
        // 修改5:can compare two tuples
        let tupleOne = (firstName:"asahi", age:25)
        let tupleTwo = (first:"asahi", a:25)
        if tupleOne == tupleTwo {
            print("equal")
        }
        else {
            print("not equal")
        }
        
        // 修改6: tuple splate syntax is deprecated.
        /*
        let parameterTuple = ("asahi", age:25)
        testFunc(parameterTuple)
         */
        
        // 修改7:var parameters is deprecated
        var name = "Tylor Swift"
        parametersFunc(name)
        parameterFuncNew(&name)
        
        // 修改8:debug identifiers are renamed
        debugFunc()
    }
    
    func selectorFunc()
    {
        print("selector function")
    }
    
    func testFunc(name: String, let age: NSInteger)
    {
        print(name+"\n",age)
    }
    /**
     *  @brief 'var' parameters are deprecated and will be removed in Swift 3.0
     */
    func parametersFunc(var name: String)
    {
        name = name.uppercaseString
        print(name)
    }

    func parameterFuncNew(inout name: String)
    {
        name = name.uppercaseString
        print(name)
    }
    
    func debugFunc()
    {
        // old version
        /*
        print(__FUNCTION__, __LINE__, __FILE__, __COLUMN__)
        */
        
        // new version
        print(#function, #line, #file, #column)
    }
    
    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
3
3
0

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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?