From c2dfe9b1123e2522ea0066f1b1703c78f23e3139 Mon Sep 17 00:00:00 2001 From: Michael Dautermann Date: Mon, 27 Nov 2017 07:40:58 -0500 Subject: [PATCH 1/2] get things compiling with Swift 3 & Xcode 8 --- .../project.pbxproj | 5 +++ TableViewCellWithAutoLayout/AppDelegate.swift | 16 ++++---- .../TableViewController/Model.swift | 20 ++++------ .../NibTableViewCell.swift | 4 +- .../TableViewController/TableViewCell.swift | 38 +++++++++---------- .../TableViewController.swift | 36 +++++++++--------- 6 files changed, 60 insertions(+), 59 deletions(-) diff --git a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj index a87308f..294df50 100644 --- a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj +++ b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj @@ -248,6 +248,9 @@ LastUpgradeCheck = 0700; ORGANIZATIONNAME = smileyborg; TargetAttributes = { + 99BCDCA018008C0000B8E66B = { + LastSwiftMigration = 0830; + }; 99BCDCBB18008C0000B8E66B = { TestTargetID = 99BCDCA018008C0000B8E66B; }; @@ -480,6 +483,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; WRAPPER_EXTENSION = app; }; name = Debug; @@ -499,6 +503,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.smileyborg.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h"; + SWIFT_VERSION = 3.0; WRAPPER_EXTENSION = app; }; name = Release; diff --git a/TableViewCellWithAutoLayout/AppDelegate.swift b/TableViewCellWithAutoLayout/AppDelegate.swift index 6b0a6d7..9d79e5e 100644 --- a/TableViewCellWithAutoLayout/AppDelegate.swift +++ b/TableViewCellWithAutoLayout/AppDelegate.swift @@ -12,39 +12,39 @@ 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. - window = UIWindow(frame: UIScreen.mainScreen().bounds) - let viewController = TableViewController(style: .Plain) + window = UIWindow(frame: UIScreen.main.bounds) + let viewController = TableViewController(style: .plain) window!.rootViewController = UINavigationController(rootViewController: viewController) window!.makeKeyAndVisible() 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:. } diff --git a/TableViewCellWithAutoLayout/TableViewController/Model.swift b/TableViewCellWithAutoLayout/TableViewController/Model.swift index b7c47d3..2ee6dbc 100644 --- a/TableViewCellWithAutoLayout/TableViewController/Model.swift +++ b/TableViewCellWithAutoLayout/TableViewController/Model.swift @@ -14,34 +14,30 @@ class Model init(populated: Bool) { if (populated) { - for familyName: AnyObject in UIFont.familyNames() { - if let familyNameString = familyName as? String { - dataArray.append((title: familyNameString, body: randomLoremIpsum())) - } + for familyNameString in UIFont.familyNames { + dataArray.append((title: familyNameString, body: randomLoremIpsum())) } } } func addSingleItem() { - let fontFamilies = UIFont.familyNames() + let fontFamilies = UIFont.familyNames - let r = random() % fontFamilies.count - let familyName: AnyObject = fontFamilies[r] + let r = Int(arc4random()) % fontFamilies.count + let familyNameString = fontFamilies[r] - if let familyNameString = familyName as? String { - dataArray.append((title: familyNameString, body: randomLoremIpsum())) - } + dataArray.append((title: familyNameString, body: randomLoremIpsum())) } func randomLoremIpsum() -> String { let loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non quam ac massa viverra semper. Maecenas mattis justo ac augue volutpat congue. Maecenas laoreet, nulla eu faucibus gravida, felis orci dictum risus, sed sodales sem eros eget risus. Morbi imperdiet sed diam et sodales. Vestibulum ut est id mauris ultrices gravida. Nulla malesuada metus ut erat malesuada, vitae ornare neque semper. Aenean a commodo justo, vel placerat odio. Curabitur vitae consequat tortor. Aenean eu magna ante. Integer tristique elit ac augue laoreet, eget pulvinar lacus dictum. Cras eleifend lacus eget pharetra elementum. Etiam fermentum eu felis eu tristique. Integer eu purus vitae turpis blandit consectetur. Nulla facilisi. Praesent bibendum massa eu metus pulvinar, quis tristique nunc commodo. Ut varius aliquam elit, a tincidunt elit aliquam non. Nunc ac leo purus. Proin condimentum placerat ligula, at tristique neque scelerisque ut. Suspendisse ut congue enim. Integer id sem nisl. Nam dignissim, lectus et dictum sollicitudin, libero augue ullamcorper justo, nec consectetur dolor arcu sed justo. Proin rutrum pharetra lectus, vel gravida ante venenatis sed. Mauris lacinia urna vehicula felis aliquet venenatis. Suspendisse non pretium sapien. Proin id dolor ultricies, dictum augue non, euismod ante. Vivamus et luctus augue, a luctus mi. Maecenas sit amet felis in magna vestibulum viverra vel ut est. Suspendisse potenti. Morbi nec odio pretium lacus laoreet volutpat sit amet at ipsum. Etiam pretium purus vitae tortor auctor, quis cursus metus vehicula. Integer ultricies facilisis arcu, non congue orci pharetra quis. Vivamus pulvinar ligula neque, et vehicula ipsum euismod quis." - let loremIpsumArray = loremIpsum.componentsSeparatedByString(" ") + let loremIpsumArray = loremIpsum.components(separatedBy: " ") let minimumNumberOfWords = 3 - let r = max(minimumNumberOfWords, random() % loremIpsumArray.count) // get a random number r, where: minimumNumberOfWords <= r <= loremIpsumArray.count + let r = max(minimumNumberOfWords, Int(arc4random()) % loremIpsumArray.count) // get a random number r, where: minimumNumberOfWords <= r <= loremIpsumArray.count let loremIpsumRandom = loremIpsumArray[0.. Int + override func numberOfSections(in tableView: UITableView) -> Int { return 1 } - override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return model.dataArray.count } - override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // This will be the case for programmatically loaded cells (see viewDidLoad to switch approaches) - if let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? TableViewCell { + if let cell: TableViewCell = tableView.dequeueReusableCell(withIdentifier: kCellIdentifier) as? TableViewCell { // Configure the cell for this indexPath cell.updateFonts() let modelItem = model.dataArray[indexPath.row] @@ -115,7 +115,7 @@ class TableViewController: UITableViewController } // This will be the case for interface builder loaded cells (see viewDidLoad to switch approaches) - if let cell: NibTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? NibTableViewCell { + if let cell: NibTableViewCell = tableView.dequeueReusableCell(withIdentifier: kCellIdentifier) as? NibTableViewCell { // Configure the cell for this indexPath cell.updateFonts() let modelItem = model.dataArray[indexPath.row] From 136937ac26765e5400f093a8038ab3386bc2e152 Mon Sep 17 00:00:00 2001 From: Michael Dautermann Date: Mon, 27 Nov 2017 07:41:12 -0500 Subject: [PATCH 2/2] add .DS_Store files to the ignore list --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 04529e0..b66e587 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,6 @@ xcuserdata # Add this line if you want to avoid checking in source code from Carthage dependencies. # Carthage/Checkouts -Carthage/Build \ No newline at end of file +Carthage/Build +.DS_Store +