This file contains hidden or 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
enum Team { | |
case iOS | |
case android | |
} | |
protocol Engineer { | |
var team: Team { get } | |
var canDevelopiOS: Bool { get } | |
} |
This file contains hidden or 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 Swiftable { | |
var isKnowSwift: Bool { get } | |
} | |
struct Steven: Engineer, Swiftable { | |
let team: Team | |
let canDevelopiOS: Bool | |
let isKnowSwift: Bool | |
} |
This file contains hidden or 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 Swiftable { | |
var isKnowSwift: Bool { get } | |
} | |
protocol Engineer { | |
var team: Team { get } | |
var canDevelopiOS: Bool { get } | |
} | |
extension Engineer { |
This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | |
} |
OlderNewer