Permalink
Browse files

update swift demo to Swift 3, modify copyright to jspatch

  • Loading branch information...
1 parent 9b60aec commit 529146e9b375738c1904c742b5c6a51723b46c50 zili.kou committed Jan 10, 2017
@@ -133,6 +133,7 @@
TargetAttributes = {
DC5FA8BE1C61F242007F1AA0 = {
CreatedOnToolsVersion = 7.2.1;
+ LastSwiftMigration = 0820;
};
};
};
@@ -293,9 +294,10 @@
INFOPLIST_FILE = SwiftDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
- PRODUCT_BUNDLE_IDENTIFIER = com.szzc.SwiftDemo;
+ PRODUCT_BUNDLE_IDENTIFIER = com.jspatch.SwiftDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SwiftDemo/SwiftDemo-Bridging-Header.h";
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -306,9 +308,10 @@
INFOPLIST_FILE = SwiftDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
- PRODUCT_BUNDLE_IDENTIFIER = com.szzc.SwiftDemo;
+ PRODUCT_BUNDLE_IDENTIFIER = com.jspatch.SwiftDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SwiftDemo/SwiftDemo-Bridging-Header.h";
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -2,7 +2,7 @@
// AppDelegate.swift
// SwiftDemo
//
-// Created by KouArlen on 16/2/3.
+// Created by jspatch on 16/2/3.
// Copyright © 2016年 Arlen. All rights reserved.
//
@@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let aClass: AnyClass? = NSClassFromString("SwiftDemo.ViewController")
@@ -33,11 +33,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print("error TestObject not found")
}
- let path = NSBundle.mainBundle().pathForResource("demo", ofType: "js")
+ let path = Bundle.main.path(forResource: "demo", ofType: "js")
do {
let patch = try String(contentsOfFile: path!)
- JPEngine.startEngine()
+ JPEngine.start()
JPEngine.evaluateScript(patch)
} catch {}
@@ -46,25 +46,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}
- func applicationWillResignActive(application: UIApplication) {
+ func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- func applicationDidEnterBackground(application: UIApplication) {
+ func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- func applicationWillEnterForeground(application: UIApplication) {
+ func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- func applicationDidBecomeActive(application: UIApplication) {
+ func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- func applicationWillTerminate(application: UIApplication) {
+ func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@@ -2,29 +2,29 @@
// TestObject.swift
// SwiftDemo
//
-// Created by KouArlen on 16/2/3.
+// Created by jspatch on 16/2/3.
// Copyright © 2016年 Arlen. All rights reserved.
//
import Foundation
/**
- After XCode 7.0(could be Swift 2.2), the Swift Class can not be marked use @objc,
+ After XCode 7.0(could be Swift 2.2), the Swift Class can not be marked using @objc,
and it can't be use in objc rumtime directly.
- So if you want use JSPatch in your project,
+ So if you want to use JSPatch in your project,
you should declare all your Swift Classes inherited from NSObject
https://forums.developer.apple.com/thread/11867
*/
-public class TestObject: NSObject {
+open class TestObject: NSObject {
/**
if your patch doesn't take effect, you should consider adding the dynamic attribute to the function
http://stackoverflow.com/questions/25651081/method-swizzling-in-swift
- In production environment, I advise you to add the dynamic attribute to all your Custom Function.
+ In production environment, I advise you to add the dynamic attribute to all your Custom Functions.
But you must know, this operation will reduce efficiency.
*/
@@ -2,7 +2,7 @@
// ViewController.swift
// SwiftDemo
//
-// Created by KouArlen on 16/2/3.
+// Created by jspatch on 16/2/3.
// Copyright © 2016年 Arlen. All rights reserved.
//
@@ -17,7 +17,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
- tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "TableViewCell")
+ tableView.register(UITableViewCell.self, forCellReuseIdentifier: "TableViewCell")
let testObject = TestObject()
testObject.testLog()
@@ -30,7 +30,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
http://stackoverflow.com/questions/25651081/method-swizzling-in-swift
- In production environment, I advise you to add the dynamic attribute to all your Custom Function.
+ In production environment, I advise you to add the dynamic attribute to all your Custom Functions.
But you must know, this operation will reduce efficiency.
*/
dynamic func testLog() {
@@ -43,16 +43,16 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
}
- func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
- func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60
}
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCellWithIdentifier("TableViewCell", forIndexPath: indexPath)
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+ let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath)
cell.textLabel?.text = NSString(format: "cell%d", indexPath.row) as String;
return cell
}

0 comments on commit 529146e

Please sign in to comment.