Skip to content

Instantly share code, notes, and snippets.

View Josscii's full-sized avatar
💭
??

Josscii Josscii

💭
??
View GitHub Profile
@Josscii
Josscii / GradientView.swift
Last active July 16, 2020 06:19
GradientView 方便布局
class GradientView: UIView {
var gradientLayer: CAGradientLayer {
return layer as! CAGradientLayer
}
override class var layerClass: AnyClass {
return CAGradientLayer.self
}
}
@Josscii
Josscii / RequestInterceptor.swift
Last active July 16, 2020 06:16
如何用 alamofire 处理 JWT 过期?(不适用于不拿http状态码做错误码的方式
// https://www.avanderlee.com/swift/authentication-alamofire-request-adapter/
/// The storage containing your access token, preferable a Keychain wrapper.
protocol AccessTokenStorage: class {
typealias JWT = String
var accessToken: JWT { get set }
}
final class RequestInterceptor: Alamofire.RequestInterceptor {
@Josscii
Josscii / maxLength.swift
Created June 3, 2020 23:12
UITextField 和 UITextView 限制最大输入长度
import UIKit
class ViewController: UIViewController {
var textField: UITextField!
var textView: UITextView!
private let maxLength = 20
override func viewDidLoad() {
super.viewDidLoad()
@Josscii
Josscii / RxSwift.md
Last active May 16, 2020 08:09
理解 RxSwift 文章备份

https://academy.realm.io/posts/krzysztof-siejkowski-mobilization-2017-rxswift-deep-cuts/ https://www.polidea.com/blog/8-Mistakes-to-Avoid-while-Using-RxSwiftPart-1/


RxSwift - Mistakes to Avoid. Part 1

Part 1: not disposing a subscription

Judging by the number of talks, articles and discussions related to reactive programming in Swift in general and the RxSwift library in particular, it looks like the community has been taken by the storm. The concept of reactiveness, however, is not a new shiny thing. The idea of using it for the development within the Apple ecosystem had been played with for a long time. Frameworks like ReactiveCocoa had existed for years and did an awesome job at bringing the reactive programming to the Objective-C. When Swift appeared with its new and exciting features, the way was paved for RxSwift, the elegant and compact port of C#-originated Reactive Extensions. It became even more convenient to go full in on the “signals as your apps’ building blocks” model.

@Josscii
Josscii / SwiftBlog.md
Created May 6, 2020 00:19
收集一些还不错的 Swift Blog
@Josscii
Josscii / AsyncOperation.swift
Created May 5, 2020 07:33
一个简单常用的异步 Operation 实现
// https://www.avanderlee.com/swift/asynchronous-operations/
class AsyncOperation: Operation {
private let lockQueue = DispatchQueue(label: "com.swiftlee.asyncoperation", attributes: .concurrent)
override var isAsynchronous: Bool {
return true
}
private var _isExecuting: Bool = false
@Josscii
Josscii / SwiftBySundell.md
Last active May 5, 2020 01:04
读 SwiftBySundell blog 学到的小技巧,截止2020.5.5,大部分内容已经快速过完

SwiftBySundell 阅读笔记

Writing small utility functions in Swift

func configure<T>(
    _ value: T,
    using closure: (inout T) throws -> Void
) rethrows -> T {
 var value = value
@Josscii
Josscii / UserDefaultsExtension.swift
Created May 4, 2020 05:15
比较好的 UserDefaults 的用法
//https://developer.apple.com/videos/play/wwdc2019/212
extension UserDefaults {
private static let isInfoBarHiddenKey = "IsInfoBarHidden"
@objc dynamic var isInfoBarHidden: Bool {
get { bool(forKey: UserDefaults.isInfoBarHiddenKey) }
set { set(newValue, forKey: UserDefaults.isInfoBarHiddenKey) }
}
}