티스토리 뷰
// closure 001
let superstar001 = { (name : String, yearOfBirth : Int) -> String in
return "name : \(name), yearOfBirth : \(yearOfBirth)"
}
print(superstar001("nature boy", 1949)) // name : nature boy, yearOfBirth : 1949
// closure 002
let superstar002 = { (name : String, yearOfBirth : Int) -> String in
"name : \(name), yearOfBirth : \(yearOfBirth)"
}
print(superstar002("dead man", 1965)) // name : dead man, yearOfBirth : 1965
// closure 003
let superstar003 = { (name : String, yearOfBirth : Int) in
"name : \(name), yearOfBirth : \(yearOfBirth)"
}
print(superstar003("never give up", 1977)) // name : never give up, yearOfBirth : 1977
// closure 004
let superstar004 : (String, Int) -> String = { name, yearOfBirth in
"name : \(name), yearOfBirth : \(yearOfBirth)"
}
print(superstar004("leukemia", 1985)) // name : leukemia, yearOfBirth : 1985
// closure 005
let superstar005 : (String, Int) -> String = {
"name : \($0), yearOfBirth : \($1)"
}
print(superstar005("3:16", 1964)) // name : 3:16, yearOfBirth : 1964
// closure - function
// closure
import UIKit
let names = ["apple", "air", "android", "banana", "note", "cat", "blue", "wrestle"]
// closure - contains
let containsSomeText : (String, String) -> Bool = { name, find in
if name.contains(find) {
return true
}
return false
}
print(containsSomeText(names[0], "a")) // result : true
print(containsSomeText(names[0], "b")) // result : false
print(containsSomeText(names[0], "p")) // result : true
// closure - first
let isStartSomeText: (String, String) -> Bool = { name, find in
if name.first?.description == find {
return true
}
return false
}
print(isStartSomeText(names[1], "a")) // result : true
print(isStartSomeText(names[1], "i")) // result : false
print(isStartSomeText(names[2], "a")) // result : true
func find(findString : String, condition: (String, String) -> Bool) -> [String] {
var newNames = [String]()
for name in names {
if condition(name, findString) {
newNames.append(name)
}
}
return newNames
}
print(find(findString: "a", condition: containsSomeText)) // result : ["apple", "air", "android", "banana", "cat"]
print(find(findString: "a", condition: isStartSomeText)) // result : ["apple", "air", "android"]
func someFind(find: String) -> [String] {
var newNames = [String]()
for name in names {
if name.contains(find) {
newNames.append(name)
}
}
return newNames
}
print(someFind(find: "n")) // result : ["android", "banana", "note"]
'ios' 카테고리의 다른 글
func (func) (0) | 2022.05.23 |
---|---|
function (0) | 2022.05.23 |
check positive number || upper case || check lower case (0) | 2022.05.22 |
if let (0) | 2022.05.21 |
print (0) | 2022.05.21 |
- Total
- Today
- Yesterday
- web view
- 화면 방향 고정
- android studio
- 클래스 이름
- 외부 브라우저
- simpleName
- defaultInputmode
- 웹뷰
- javaClass
- logcat
- web chrome view
- 영문 키보드
- 로그캣
- web view settings
- 코틀린
- Inputmode
- new project
- custom web view
- StringWriter
- andorid
- create project
- Android
- screenorientation
- check permissions
- 안드로이드
- create new project
- permissions
- 화면 고정
- kotlin
- logtag
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |