Skip to content

Instantly share code, notes, and snippets.

View zyuanming's full-sized avatar
🎯
Focusing

YuanMing zyuanming

🎯
Focusing
View GitHub Profile
@zyuanming
zyuanming / expand.swift
Last active July 8, 2019 05:14
cell expand and collaps with animation
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let cell = tableView.cellForRow(at: indexPath) as? FilmTableViewCell else { return }
var film = selectedAuteur.films[indexPath.row]
film.isExpanded = !film.isExpanded
selectedAuteur.films[indexPath.row] = film
cell.moreInfoTextView.text = film.isExpanded ? film.plot : moreInfoText
cell.moreInfoTextView.textAlignment = film.isExpanded ? .left : .center
cell.moreInfoTextView.textColor = film.isExpanded ? UIColor(red:0.75, green:0.75, blue:0.75, alpha:1.0) : .red
tableView.beginUpdates()
tableView.endUpdates()
@zyuanming
zyuanming / genericprotocol.swift
Created November 27, 2017 10:02
Swift Generic Protocol Test
protocol ProtoA {
func helloA()
}
protocol ProtoB : ProtoA {
func helloB()
}
infix operator >>>
func >>> <T: ProtoA>(left: T, right: Int) {
@zyuanming
zyuanming / Reactive.swift
Created October 5, 2017 17:34
UIKonf 2017 – Day 1 –Thomas Visser – Reactive Programming From Scratch
var z = 0
let s = AnyIterator { () -> Int in
defer { z += 1 }
return z
}
for i in s.lazy.prefix(3) {
print(i)
}
@zyuanming
zyuanming / >>>.swift
Created October 4, 2017 15:16
UIKonf 2017 – Day 2 – Brandon Williams & Lisa Luo – Anything you can do, I can do better
infix operator >>> : MultiplicationPrecedence
func >>> <A, B, C>(f: @escaping (A) -> B,
g: @escaping (B) -> C) -> (A) -> C {
return { g(f($0)) }
}
func incr(_ x: Int) -> Int { return x + 1 }
func square(_ x: Int) -> Int { return x * x }
@zyuanming
zyuanming / IntermediateTypes.swift
Created October 3, 2017 17:22
UIKonf 2017 – Day 2 – Chris Eidhof & FlorianKugler – Intermediate Types
struct KeyboardWillShowPayload {
let endFrame: CGRect
init(userInfo: [AnyHashable: Any]) {
endFrame = userInfo[UIKeyboardFrameEndUserInfoKey] as! CGRect
}
}
@zyuanming
zyuanming / TransitionAnimation.swift
Created August 22, 2017 09:21
TransitionAnimation.swift
extension UIView {
public func fadeTransit(duration: TimeInterval = 0.2) {
let transition = CATransition() <- {
$0.duration = duration
$0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
$0.type = kCATransitionFade
}
self.layer.add(transition, forKey: nil)
}
@zyuanming
zyuanming / RoundImage.swift
Created August 1, 2017 08:53
RoundImage.swift
private func strokedRoundImage(fromImage image: UIImage?,
size: CGSize,
color: UIColor,
lineWidth: CGFloat = 1.0) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
defer { UIGraphicsEndImageContext() }
let innerRect = CGRect(x: 1.0, y: 1.0, width: size.width - 2.0, height: size.height - 2.0)
image?.draw(in: innerRect)
class AsyncImageView: UIView {
private var _image: UIImage?
var image: UIImage? {
get {
return _image
}
set {
@zyuanming
zyuanming / kdebug_signpost_start.swift
Created July 7, 2017 09:52
kdebug_signpost_start
kdebug_signpost_start(10, 0, 0, 0, 0)
// your test code
kdebug_signpost_end(10, 0, 0, 0, 0)
let urlSession = URLSession.shared
let dlTask: URLSessionDownloadTask = urlSession.downloadTask(with: url)
kdebug_signpost_start(20, (uintptr_t)dlTask, 0, 0, 0)
// your test code
kdebug_signpost_end(20, (uintptr_t)dlTask, 0, 0, 0)
@zyuanming
zyuanming / Fabric Build Script
Created June 6, 2017 09:15
Fabric Build script
file="${PROJECT_DIR}/Confidential/env.plist"
if [ -f $file ]
then
echo "env.plist found."
FABRIC_SECRET=$(/usr/libexec/PlistBuddy -c "Print :FabricSecret" $file)
FABRIC_API_KEY=$(/usr/libexec/PlistBuddy -c "Print :Fabric:APIKey" "${PROJECT_DIR}/Potatso/Info.plist")
else
echo "env.plist not found."
FABRIC_SECRET="fake secret"
FABRIC_API_KEY="0000000000000000000000000000000000000000"