//函数
func eatTomatos(a: Int, b: Int) -> Int {
return a + b
}
//嵌套函数
func eatTomatos(a: Int, b: Int) -> Int {
//嵌套函数
func digest(a: Int, b: Int) -> Int {
return 2 * a + b
}
return digest(a: a, b: b)
}
//闭包
var eatTomatos = {(a: Int, b: Int) -> Int in
return a + b
}
override func viewDidLoad() {
super.viewDidLoad()
print(eatTomatos(a: 1, b: 2))//③
print(eatTomatos(a: 2, b: 3))//④
}
func eatTomatos(a: Int, b: Int) -> Int {
var numArray: Array<Int> = Array.init()
//嵌套函数
func digest(a: Int, b: Int) -> Int {
numArray.append(a)
numArray.append(b)
print(numArray.count)//②
return 2 * a + b
}
print(numArray.count)//①
return digest(a: a, b: b)
}
//打印的结果依次(①②③④)是:
0
2
4
0
2
7
// 作为参数
override func viewDidLoad() {
super.viewDidLoad()
cookTomates { (a, b) in
print(a)
print(b)
}
}
func cookTomates(tomato: (Int, Int) -> Void){
tomato(1, 2)
}
//作为返回值
override func viewDidLoad() {
super.viewDidLoad()
let tomato = gainTomatos()
print(tomato(2, 3))
}
var eatTomatos: (Int, Int) -> Int = {(a: Int, b: Int) -> Int in
return a + b
}
func gainTomatos() -> (Int, Int) -> Int {
return eatTomatos
}
typealias Tomato = (Int, Int) -> Int
override func viewDidLoad() {
super.viewDidLoad()
let tomato = gainTomatos()
print(tomato(2, 3))
}
var eatTomatos: Tomato = {(a: Int, b: Int) -> Int in
return a + b
}
func gainTomatos() -> Tomato {
return eatTomatos
}
override func viewDidLoad() {
super.viewDidLoad()
let a: A = A()
a.fromB()
}
typealias Tomato = (Int, Int) -> Int
class A: NSObject {
let b: B = B()
func fromB() {
b.tomato = {
(x, y) -> Int in
return x + y
}
print(b.toA())
}
}
class B: NSObject {
var tomato: Tomato?
func toA() -> Int {
let a = 3
let b = 4
return tomato!(a, b)
}
}
import UIKit
import Alamofire
import SwiftyJSON
class ZYLResponse: NSObject {
//接收数据是否成功
var isSuccess: Bool = false
//接收到的字典数据
var dict: Dictionary<String, Any>?
//接收到的数组数据
var array: Array<Any>?
//错误信息
var error: Error?
//JSON
var json:JSON?
}
typealias DataReply = (ZYLResponse) -> Void
class ZYLNetTool: NSObject {
///POST请求
open static func post(url: String, parameters: Dictionary<String, Any>?, complete: @escaping DataReply) {
Alamofire.request(url, method: .post, parameters: parameters).responseJSON { (response) in
let myResponse = ZYLResponse()
myResponse.isSuccess = response.result.isSuccess
myResponse.dict = response.result.value as! Dictionary<String, Any>?
myResponse.array = response.result.value as? Array<Any>
myResponse.error = response.result.error
myResponse.json = JSON(data: response.data!)
complete(myResponse)
}
}
///GET请求
open static func get(url: String, parameters: Dictionary<String, Any>?, complete: @escaping DataReply) {
Alamofire.request(url, method: .get, parameters: parameters).responseJSON { (response) in
let myResponse = ZYLResponse()
myResponse.isSuccess = response.result.isSuccess
myResponse.dict = response.result.value as! Dictionary<String, Any>?
myResponse.array = response.result.value as? Array<Any>
myResponse.error = response.result.error
myResponse.json = JSON(data: response.data!)
complete(myResponse)
}
}
}
//调用
ZYLNetTool.post(url: HTTP_ACTIVATE_PORT, parameters: paraDict, complete: { (response) in
if response.isSuccess {
//请求数据成功
} else {
//请求数据失败
}
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有