Skip to content

Instantly share code, notes, and snippets.

View AppleCEO's full-sized avatar
💻

도미닉 AppleCEO

💻
View GitHub Profile
@AppleCEO
AppleCEO / backgroundColor.swift
Created June 13, 2019 09:03
background color set
descriptionAttributedString.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.blue, range: NSRange(location: 0, length: 2))
@AppleCEO
AppleCEO / opacityBackground.swift
Created June 13, 2019 09:05
50% opacity background
attributedString.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.black.withAlphaComponent(0.5), range: NSRange(location: 5, length: 4))
@AppleCEO
AppleCEO / buttonTouched.swift
Created June 13, 2019 09:22
when button touched attribute change
@IBAction func nextButtonTouched(_ sender: Any) {
self.firstLabel.textColor = UIColor.blue
self.firstLabel.backgroundColor = UIColor.yellow
self.firstLabel.alpha = 0.5
}
@AppleCEO
AppleCEO / monad.swift
Created June 13, 2019 12:08
array is monad
let array = [1, 2, 3, 4, 5]
let arrayReturned = array.map({ (number: Int) -> Int in
let result = 2 * number
return result
}).map({ (number: Int) -> Int in
let result = number / 2
return result
})
@AppleCEO
AppleCEO / setIsFunctor.swift
Created June 13, 2019 12:12
Set is functor
let set:Set = [1, 2, 3, 4, 5]
let setReturned = set.map({ (number: Int) -> Int in
let result = 2 * number
return result
})
@AppleCEO
AppleCEO / optionalIsMonad.swift
Created June 13, 2019 12:19
Optional is monad
let optional:Optional = 1
let optionalReturned = optional.map({ (number: Int) -> Int in
let result = 2 * number
return result
}).map({ (number: Int) -> Int in
let result = number / 2
return result
})
@AppleCEO
AppleCEO / dictionaryIsFunctor.swift
Created June 13, 2019 12:34
Dictionary is functor
let dictionary:Dictionary = [1:"int",3:"hi"]
let dictionaryReturned = dictionary.map({ (key: Int, value: String) -> Int in
let result = 2 * key
return result
})
@AppleCEO
AppleCEO / GenericAndCustomOperators.swift
Last active June 17, 2019 08:36
Generic and Custom Operators Swift Example
protocol Multipleiable {
static func * (lhs: Self, rhs: Self) -> Self
}
extension Int: Multipleiable {}
extension Double: Multipleiable {}
infix operator ** : MultiplicationPrecedence
func **<T> (lhs: T, rhs: T) -> T where T: Multipleiable {
infix operator ** : MultiplicationPrecedence
func ** (lhs: Int, rhs: Int) -> Int {
return lhs * rhs
}
3 ** 4
// result : 12
@AppleCEO
AppleCEO / generic1.swift
Created June 18, 2019 01:47
Generic example 1
func **<T> (lhs: T, rhs: T) -> T where T: Multipleiable {
return lhs * rhs
}