Skip to content

Instantly share code, notes, and snippets.

View KrisYu's full-sized avatar

Xue Yu KrisYu

View GitHub Profile
@KrisYu
KrisYu / forgetyou.js
Last active September 27, 2018 12:44
豆瓣广播📢屏蔽友邻的脚本。
// ==UserScript==
// @name forgetyou
// @namespace forgetyou
// @include https://www.douban.com/*
// @version 1.1
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==
@KrisYu
KrisYu / DragContainer.swift
Created February 25, 2018 03:12
Drag and Drop for macos
import Cocoa
protocol DragContainerDelegate {
func draggingEntered()
func draggingExit()
func draggingFileAccept(_ files: [URL])
}
// https://stackoverflow.com/questions/29233247/implementing-a-drag-and-drop-zone-in-swift
class DragContainer: NSView {
func addAlbumAtIndex(album: Album, index: Int) {
LibraryAPI.shared.addAlbum(album, at: index)
currentAlbumIndex = index
// everytime we change the albums, we need to reload the data and table.
allAlbums = LibraryAPI.shared.getAlbums()
horizontalScrollerView.reload()
showDataForAlbum(at: currentAlbumIndex)
}
// 1. define Album Codalble
struct Album: Codable {
let title : String
let artist : String
let genre : String
let coverUrl : String
let year : String
}
// 1. 在 Storyboard 中设置RestorationID
// 2. AppDelegate.swift中告诉App我们想要save和restore
func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
return true
}
func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
return true
}
// 📢名字:放在NSNotificationExtension.swift中,作为广播名字
extension NSNotification.Name {
static let BLDownloadImage = Notification.Name("BLDownloadImageNotification")
}
// 📢发送:放在 AlbumView.swift中
init(frame: CGRect, coverUrl: String) {
super.init(frame: frame)
commonInit()
//
// HorizontalScrollerView.swift
// RWBlueLibrary
//
// Created by Xue Yu on 2/4/18.
// Copyright © 2018 Razeware LLC. All rights reserved.
//
import UIKit
// 把 DataSource 和 Delegate 协议分开,这样更优雅,并且可以减少不必要的 @objc 的使用
class Person: NSObject, Codable {
var firstName: String
var lastName: String
override var description: String {
return self.firstName + " " + self.lastName
}
struct Person: Codable {
var firstName: String
var lastName: String
var name: Data? {
return try? PropertyListEncoder().encode(self)
}
class Person: NSObject, NSCoding {
var firstName: String
var lastName: String
override var description: String {
return self.firstName + " " + self.lastName
}