Selaa lähdekoodia

Update example project for Swift 3 (#376)

Michael Buxton 9 vuotta sitten
vanhempi
commit
32cd509939

+ 8 - 9
Example-iOS/AppDelegate.swift

@@ -13,19 +13,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
 
     var window: UIWindow?
 
-    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
-        
-        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
-        
+    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
+
+        self.window = UIWindow(frame: UIScreen.main.bounds)
+
         let listViewController:ListViewController = ListViewController()
         let navigationController:UINavigationController = UINavigationController(rootViewController: listViewController);
-        
+
         self.window!.rootViewController = navigationController;
-        
-        self.window!.backgroundColor = UIColor.whiteColor()
+ 
+        self.window!.backgroundColor = UIColor.white
         self.window!.makeKeyAndVisible()
         
         return true
     }
-}
-
+}

+ 12 - 13
Example-iOS/ListViewController.swift

@@ -13,35 +13,34 @@ class ListViewController: UITableViewController {
 
     let kCellIdentifier = "CellIdentifier"
     let demos = ["Simple Layout", "Basic UIScrollView"]
-    
+
     override func viewDidLoad() {
         super.viewDidLoad()
         
         self.title = "SnapKit iOS Demos"
         
-        self.tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: kCellIdentifier)
+        self.tableView?.register(UITableViewCell.self, forCellReuseIdentifier: kCellIdentifier)
     }
-
-    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
-        let cell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier)! as UITableViewCell
+    
+    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+        return demos.count
+    }
+    
+    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+        let cell = tableView.dequeueReusableCell(withIdentifier: kCellIdentifier)! as UITableViewCell
         
         cell.textLabel?.text = demos[indexPath.row]
         
         return cell
     }
     
-    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        return demos.count
-    }
-    
-    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
+    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         if indexPath.row == 0 {
             let viewController = SimpleLayoutViewController()
             navigationController?.pushViewController(viewController, animated: true)
         } else if indexPath.row == 1 {
-            let viewController = BasicUIScrollViewController()
+            let viewController = ViewController()
             navigationController?.pushViewController(viewController, animated: true)
         }
     }
-}
-
+}

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 4 - 4
Example-iOS/demos/BasicUIScrollViewController.swift


+ 25 - 26
Example-iOS/demos/SimpleLayoutViewController.swift

@@ -14,38 +14,38 @@ class SimpleLayoutViewController: UIViewController {
 
     let blackView: UIView = {
         let view = UIView()
-        view.backgroundColor = .blackColor()
+        view.backgroundColor = .black
         return view
     }()
 
     let redView: UIView = {
         let view = UIView()
-        view.backgroundColor = .redColor()
+        view.backgroundColor = .red
         return view
     }()
 
     let yellowView: UIView = {
         let view = UIView()
-        view.backgroundColor = .yellowColor()
+        view.backgroundColor = .yellow
         return view
     }()
 
     let blueView: UIView = {
         let view = UIView()
-        view.backgroundColor = .blueColor()
+        view.backgroundColor = .blue
         return view
     }()
 
     let greenView: UIView = {
         let view = UIView()
-        view.backgroundColor = .greenColor()
+        view.backgroundColor = .green
         return view
     }()
 
     override func viewDidLoad() {
         super.viewDidLoad()
 
-        view.backgroundColor = UIColor.whiteColor()
+        view.backgroundColor = UIColor.white
 
         view.addSubview(blackView)
         view.addSubview(redView)
@@ -60,33 +60,33 @@ class SimpleLayoutViewController: UIViewController {
 
         if (!didSetupConstraints) {
 
-            blackView.snp_makeConstraints { make in
+            blackView.snp.makeConstraints { make in
                 make.center.equalTo(view)
-                make.size.equalTo(CGSizeMake(100.0, 100.0))
+                make.size.equalTo(CGSize(width: 100, height: 100))
             }
 
-            redView.snp_makeConstraints { make in
-                make.top.equalTo(blackView.snp_bottom).offset(20.0)
-                make.right.equalTo(blackView.snp_left).offset(-20.0)
-                make.size.equalTo(CGSizeMake(100.0, 100.0))
+            redView.snp.makeConstraints { make in
+                make.top.equalTo(blackView.snp.bottom).offset(20.0)
+                make.right.equalTo(blackView.snp.left).offset(-20.0)
+                make.size.equalTo(CGSize(width: 100, height: 100))
             }
 
-            yellowView.snp_makeConstraints { make in
-                make.top.equalTo(blackView.snp_bottom).offset(20.0)
-                make.left.equalTo(blackView.snp_right).offset(20.0)
-                make.size.equalTo(CGSizeMake(100.0, 100.0))
+            yellowView.snp.makeConstraints { make in
+                make.top.equalTo(blackView.snp.bottom).offset(20.0)
+                make.left.equalTo(blackView.snp.right).offset(20.0)
+                make.size.equalTo(CGSize(width: 100, height: 100))
             }
 
-            blueView.snp_makeConstraints { make in
-                make.bottom.equalTo(blackView.snp_top).offset(-20.0)
-                make.left.equalTo(blackView.snp_right).offset(20.0)
-                make.size.equalTo(CGSizeMake(100.0, 100.0))
+            blueView.snp.makeConstraints { make in
+                make.bottom.equalTo(blackView.snp.top).offset(-20.0)
+                make.left.equalTo(blackView.snp.right).offset(20.0)
+                make.size.equalTo(CGSize(width: 100, height: 100))
             }
 
-            greenView.snp_makeConstraints { make in
-                make.bottom.equalTo(blackView.snp_top).offset(-20.0)
-                make.right.equalTo(blackView.snp_left).offset(-20.0)
-                make.size.equalTo(CGSizeMake(100.0, 100.0))
+            greenView.snp.makeConstraints { make in
+                make.bottom.equalTo(blackView.snp.top).offset(-20.0)
+                make.right.equalTo(blackView.snp.left).offset(-20.0)
+                make.size.equalTo(CGSize(width: 100, height: 100))
             }
 
             didSetupConstraints = true
@@ -94,5 +94,4 @@ class SimpleLayoutViewController: UIViewController {
 
         super.updateViewConstraints()
     }
-
-}
+}

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä