Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
I may be slow to respond.

DianQK DianQK

:shipit:
I may be slow to respond.
View GitHub Profile
View Example.swift
let CampusNetworkProvider = MoyaProvider<CampusNetwork>(endpointClosure: MoyaProvider.DefaultEndpointMapping,
requestClosure: requestClosure,
stubClosure: MoyaProvider.NeverStub,
manager: MoyaProvider<CampusNetwork>.DefaultAlamofireManager(),
plugins: [NetworkLoggerPlugin()])
View SearchParentView.swift
import UIKit
func recurisiveSearchParentViewUntil<T: UIView>(type: T.Type, currentView: UIView) -> T? {
switch currentView {
case let view as T:
return view // 当前 view 满足则返回 view
case let view where view.superview != nil:
return recurisiveSearchParentViewUntil(type, currentView: view.superview!)
default:
return nil
View Async.swift
enum Result<T> {
case Success(T)
case Failure(ErrorType)
}
extension Result {
static func unit(x: T) -> Result<T> {
return .Success(x)
}
View Swifty.md
struct Phone {
    var number: String?
    var originalLabel: String?
    
    init(number: String? = nil, originalLabel: String? = nil) {
        self.number = number
        self.originalLabel = originalLabel
    }
}
View 用更 Swifty 的代码遍历数据.swift
import UIKit
extension SequenceType {
/// flatMap 出我们需要的类型
///
/// - Complexity: O(*M* + *N*), where *M* is the length of `self`
/// and *N* is the length of the result.
@warn_unused_result
public func flatMap<T>(type type: T.Type) -> [T] {
return flatMap { $0 as? T }
View RRLazyJunCore.swift
typealias Filter = CIImage -> CIImage
struct RRLazyJunCore {
let filter: Filter
init(filter: Filter = { $0 }) { // 这个就比较尴尬了
self.filter = filter
}
}
View StopWhenTap.swift
import UIKit
import RxSwift
import RxCocoa
import NSObject_Rx
class ViewController: UIViewController {
@IBOutlet var stop: UIButton!
let timer = Observable<Int>.interval(1, scheduler: MainScheduler.instance)
View SCal.swift
enum CalculatorError: ErrorType {
case RejectCharacter(Character) // 不接受的字符
case ActionNilXXX // * / 乘除前面没有 可以值
case ActionDuplicate // 符号写一起了,白痴
case ParenthesesDuplicate // 多写了个 )
}
enum CalculatorNode: CustomStringConvertible {
case number(String)
case action(Character)
View Annotations.swift
//
// ViewController.swift
// Annotations
//
// Created by 宋宋 on 18/09/2016.
// Copyright © 2016 DianQK. All rights reserved.
//
import UIKit
import RxSwift
View Rule.swift
struct Rule {
let index1: Int
let index2: Int
let index3: Int
let result: (_ value1: Int, _ value2: Int, _ value3: Int) -> Int
}
let rules: [Rule] = {
var rules: [Rule] = []