zoukankan      html  css  js  c++  java
  • swift版的元组

    swift版的元组

    说明

    元组的内容并不多,使用的话跟普通变量类似,以下是测试源码:

    //
    //  ViewController.swift
    //  Tuples
    //
    //  Created by YouXianMing on 15/10/12.
    //
    
    import UIKit
    
    class ViewController: UIViewController {
    
        var tuplesValues : (duration : NSTimeInterval, animated : Bool)?
        
        override func viewDidLoad() {
            
            super.viewDidLoad()
            
            unnamedTuples()
            
            namedTuples()
            
            tuplesValues = (duration : 10, animated : true)
            if let _ = tuplesValues {
            
                print(tuplesValues!.duration)
                print(tuplesValues!.animated)
                
            } else {
            
            }
        }
        
        // Unnamed Tuples
        func unnamedTuples() {
        
            let tipAndTotalOne = (4.00, 25.19)
            let tipAndTotalTwo : (Double, Double) = (4.00, 25.19)
            
            print(tipAndTotalOne)
            print(tipAndTotalTwo)
        }
        
        // Named Tuples
        func namedTuples() {
        
            let tipAndTotalNamedOne = (tipAmt : 4.00, total : 25.19)
            print("(tipAndTotalNamedOne.tipAmt) + (tipAndTotalNamedOne.total)")
            
            let tipAndTotalNamedTwo : (tipAmt : Double, total : Double) = (4.00, 25.19)
            print("(tipAndTotalNamedTwo.tipAmt) + (tipAndTotalNamedTwo.total)")
        }
        
        // Returning Tuples
        func calcTipWithTipPct(tipPct:Double) -> (tipAmt : Double, total : Double) {
            
            let tipAmt     = tipPct * 6
            let finalTotal = tipAmt * 0.56
            
            return (tipAmt, finalTotal)
        }
        
        // animationOptionsWith
        func animationOptionsWith(duration : NSTimeInterval, animated : Bool) {
        
        }
    }

    细节

  • 相关阅读:
    Sqlsugar中使用Codefrist创建数据库
    EFCore中CoreFrist多个上下文
    高并发
    优先级反转
    二叉树算法
    使用AJAX上传图片
    Entity Framework
    .Net面试题
    LC 1515. Best Position for a Service Centre (Simulated Annealing)
    git
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4871622.html
Copyright © 2011-2022 走看看