Skip to content

Instantly share code, notes, and snippets.

@stevenchou1130
stevenchou1130 / videoJSON.txt
Last active November 11, 2019 11:31 — forked from jsturgis/gist:3b19447b304616f18657
public test videos
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
extension String {
func versionToInt() -> [Int] {
return self.components(separatedBy: ".").map { Int.init($0) ?? 0 }
}
}
let currentVersion = appVersion.versionToInt()
let storeVersion = json["results"][0]["version"].stringValue.versionToInt()
let isCurrentVersionNewer = storeVersion.lexicographicallyPrecedes(currentVersion)
let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String
let storeVersion = json["results"][0]["version"].stringValue
if appVersion == storeVersion {
// 已是最新版本
} else {
// Do something
}
import UIKit
import SwiftyJSON
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print(steven.description)
// I belong to iOS team.
protocol Engineer: CustomStringConvertible {
var team: Team { get }
var canDevelopiOS: Bool { get }
}
extension CustomStringConvertible where Self: Engineer {
var description: String {
switch team {
case .android:
return "I belong to Android team."
struct Sam: Engineer, Swiftable {
let team: Team
let isKnowSwift: Bool
}
let sam = Sam(team: .android, isKnowSwift: true)
print("Sam can develop iOS: \(sam.canDevelopiOS)")
// Sam can develop iOS: true
struct Sam: Engineer {
let team: Team
let canDevelopiOS: Bool
}
let sam = Sam(team: .android, canDevelopiOS: true)
print("Sam can develop iOS: \(sam.canDevelopiOS)”)
// Sam can develop iOS: true
struct Sam: Engineer {
let team: Team
}
let sam = Sam(team: .android)
print("Sam can develop iOS: \(sam.canDevelopiOS)”)
// Sam can develop iOS: false