This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
func versionToInt() -> [Int] { | |
return self.components(separatedBy: ".").map { Int.init($0) ?? 0 } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let currentVersion = appVersion.versionToInt() | |
let storeVersion = json["results"][0]["version"].stringValue.versionToInt() | |
let isCurrentVersionNewer = storeVersion.lexicographicallyPrecedes(currentVersion) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String | |
let storeVersion = json["results"][0]["version"].stringValue | |
if appVersion == storeVersion { | |
// 已是最新版本 | |
} else { | |
// Do something | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SwiftyJSON | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(steven.description) | |
// I belong to iOS team. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Sam: Engineer { | |
let team: Team | |
} | |
let sam = Sam(team: .android) | |
print("Sam can develop iOS: \(sam.canDevelopiOS)”) | |
// Sam can develop iOS: false |
NewerOlder