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) {
        
        }
    }

    细节

  • 相关阅读:
    IDEA右键新建时没有Java Class选项
    捕获摄像头视频VC
    重叠IO与IOCP
    (八)内存管理与内存分配
    DebugView使用详解
    (六) 中断机制
    (五) proc文件系统
    bash 之备份文件
    bash 遍历目录文件
    (四) linux内核模块编程
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4871622.html
Copyright © 2011-2022 走看看