From 1321c249da71063b0c291ae7cd9b0c765574c99d Mon Sep 17 00:00:00 2001 From: Matt Jackson Date: Sat, 12 Sep 2015 16:04:34 +0100 Subject: [PATCH 1/5] swift code section not closed before objc section --- 2013-12-02-nsnotification-and-nsnotificationcenter.md | 1 + 1 file changed, 1 insertion(+) diff --git a/2013-12-02-nsnotification-and-nsnotificationcenter.md b/2013-12-02-nsnotification-and-nsnotificationcenter.md index eba87182..baceb91a 100644 --- a/2013-12-02-nsnotification-and-nsnotificationcenter.md +++ b/2013-12-02-nsnotification-and-nsnotificationcenter.md @@ -152,6 +152,7 @@ Something that often slips up developers is how similar the method signatures fo func addObserver(observer: NSObject, forKeyPath keyPath: String, options: NSKeyValueObservingOptions, context: UnsafeMutablePointer) +~~~ ~~~{objective-c} - (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath From 1ecfa2a0bde86dec5c8fd376a8483972b893763d Mon Sep 17 00:00:00 2001 From: Roman Roibu Date: Sat, 12 Sep 2015 19:55:22 +0300 Subject: [PATCH 2/5] Update iOS 7 article for Swift 2.0 --- 2013-09-23-ios7.md | 47 +++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/2013-09-23-ios7.md b/2013-09-23-ios7.md index 96c77806..1d7e106a 100644 --- a/2013-09-23-ios7.md +++ b/2013-09-23-ios7.md @@ -4,8 +4,8 @@ author: Mattt Thompson category: "" excerpt: "With the NDA finally lifted, we can finally talk about all of the amazing new APIs in iOS 7." status: - swift: 1.1 - reviewed: May 20, 2015 + swift: 2.0 + reviewed: Sep 12, 2015 --- With the NDA finally lifted, we can finally talk about all of the amazing new APIs in iOS 7. And there are a _lot_ of them. "1500 new APIs", by Apple's count during the WWDC Keynote. (Granted, a good portion of that could just be all of the changes from `id` to `instancetype`, but that's a huge number, regardless). @@ -25,9 +25,9 @@ But no longer! iOS 7 finally bakes-in Base64: ~~~{swift} let string = "Lorem ipsum dolor sit amet." if let data = string.dataUsingEncoding(NSUTF8StringEncoding) { - let base64EncodedString = data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros) - - println(base64EncodedString) // TG9yZW0gaXBzdW0gZG9sYXIgc2l0IGFtZXQu + let base64EncodedString = data.base64EncodedStringWithOptions([]) + + print(base64EncodedString) // TG9yZW0gaXBzdW0gZG9sYXIgc2l0IGFtZXQu } ~~~ @@ -49,8 +49,8 @@ if let components = NSURLComponents(string: "http://nshipster.com") { components.path = "/iOS7" components.query = "foo=bar" - println(components.scheme!) // http - println(components.URL!) // http://nshipster.com/iOS7?foo=bar + print(components.scheme!) // http + print(components.URL!) // http://nshipster.com/iOS7?foo=bar } ~~~ @@ -86,7 +86,7 @@ Anything with a notion of completed and total units is a candidate for `NSProgre let progress = NSProgress(totalUnitCount: 100) progress.completedUnitCount = 42; -println(progress.localizedDescription) // 42% completed +print(progress.localizedDescription) // 42% completed ~~~ ~~~{objective-c} @@ -133,8 +133,8 @@ Behold! ~~~{swift} let array = [1, 2, 3] as NSArray -println("First Object: \(array.firstObject)") // First Object: Optional(1) -println("Last Object: \(array.lastObject)") // Last Object: Optional(3) +print("First Object: \(array.firstObject)") // First Object: Optional(1) +print("Last Object: \(array.lastObject)") // Last Object: Optional(3) ~~~ ~~~{objective-c} @@ -161,8 +161,9 @@ let smileDetector = CIDetector(ofType: CIDetectorTypeFace, context: context, options: [CIDetectorTracking: true, CIDetectorAccuracy: CIDetectorAccuracyLow]) var features = smileDetector.featuresInImage(ciImage, options: [CIDetectorSmile: true]) + if let feature = features.first as? CIFaceFeature where feature.hasSmile { - UIImageWriteToSavedPhotosAlbum(UIImage(CIImage: ciImage)!, self, "didFinishWritingImage", &features) + UIImageWriteToSavedPhotosAlbum(UIImage(CIImage: ciImage), self, "didFinishWritingImage", &features) } else { label.text = "Say Cheese!" } @@ -194,11 +195,11 @@ let session = AVCaptureSession() let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) var error: NSError? -let input = AVCaptureDeviceInput(device: device, error: &error) -if let error = error { - println("Error: \(error)") -} else { +do { + let input = try AVCaptureDeviceInput(device: device) session.addInput(input) +} catch let error { + print("Error: \(error)") } let output = AVCaptureMetadataOutput() @@ -214,7 +215,7 @@ func captureOutput( captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) { - + var QRCode: String? for metadata in metadataObjects as! [AVMetadataObject] { if metadata.type == AVMetadataObjectTypeQRCode { @@ -223,7 +224,7 @@ func captureOutput( } } - println("QRCode: \(QRCode)") + print("QRCode: \(QRCode)") } ~~~ @@ -290,9 +291,13 @@ Even though the number of people who have actually read something saved for late ~~~{swift} import SafariServices -let url = NSURL(string: "http://nshipster.com/ios7") -SSReadingList.defaultReadingList().addReadingListItemWithURL(url, title: "NSHipster", - previewText: "...", error: nil) +let url = NSURL(string: "http://nshipster.com/ios7")! +do { + try SSReadingList.defaultReadingList()?.addReadingListItemWithURL(url, title: "NSHipster", + previewText: "...") +} catch let error { + print("Error: \(error)") +} ~~~ ~~~{objective-c} @@ -345,7 +350,7 @@ let distance = portland.distanceFromLocation(sanFrancisco) let formatter = MKDistanceFormatter() formatter.units = .Imperial -println(formatter.stringFromDistance(distance)) // 535 miles +print(formatter.stringFromDistance(distance)) // 535 miles ~~~ ~~~{objective-c} From f87ecdb3b0a17ad2890ec75b9df7b16d57b36078 Mon Sep 17 00:00:00 2001 From: Roman Roibu Date: Sat, 12 Sep 2015 20:41:36 +0300 Subject: [PATCH 3/5] Update iOS 8 article for Swift 2.0 --- 2014-06-09-ios8.md | 90 +++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/2014-06-09-ios8.md b/2014-06-09-ios8.md index 575d1284..74f80ab0 100644 --- a/2014-06-09-ios8.md +++ b/2014-06-09-ios8.md @@ -4,7 +4,8 @@ author: Mattt Thompson category: "" excerpt: "Ask anyone, and they'll tell you: WWDC 2014 was the one of the most exciting in recent memory. This week, we'll take a look beneath the headline features, and share some of the more obscure APIs that everyone should know about." status: - swift: 1.0 + swift: 2.0 + reviewed: Sep 12, 2015 --- Ask anyone, and they'll tell you: WWDC 2014 was one of the most exciting in recent memory. It was, first and foremost, a developer event, with nary a hardware announcement to upstage the latest software & developer tools. @@ -51,7 +52,7 @@ let energyFormatter = NSEnergyFormatter() energyFormatter.forFoodEnergyUse = true let joules = 10_000.0 -println(energyFormatter.stringFromJoules(joules)) // "2.39 Cal" +print(energyFormatter.stringFromJoules(joules)) // "2.39 Cal" ~~~ ### NSMassFormatter @@ -61,7 +62,7 @@ Although the fundamental unit of physical existence, mass is pretty much relegat ~~~{swift} let massFormatter = NSMassFormatter() let kilograms = 60.0 -println(massFormatter.stringFromKilograms(kilograms)) // "132 lb" +print(massFormatter.stringFromKilograms(kilograms)) // "132 lb" ~~~ ### NSLengthFormatter @@ -71,7 +72,7 @@ Rounding out the new `NSFormatter` subclasses is `NSLengthFormatter`. Think of i ~~~{swift} let lengthFormatter = NSLengthFormatter() let meters = 5_000.0 -println(lengthFormatter.stringFromMeters(meters)) // "3.107 mi" +print(lengthFormatter.stringFromMeters(meters)) // "3.107 mi" ~~~ ## CMPedometer @@ -86,15 +87,16 @@ import CoreMotion let lengthFormatter = NSLengthFormatter() let pedometer = CMPedometer() pedometer.startPedometerUpdatesFromDate(NSDate(), withHandler: { data, error in - if !error { - println("Steps Taken: \(data.numberOfSteps)") + if let data = data { + print("Steps Taken: \(data.numberOfSteps)") - let distance = data.distance.doubleValue - println("Distance: \(lengthFormatter.stringFromMeters(distance))") + if let distance = data.distance?.doubleValue { + print("Distance: \(lengthFormatter.stringFromMeters(distance))") - let time = data.endDate.timeIntervalSinceDate(data.startDate) - let speed = distance / time - println("Speed: \(lengthFormatter.stringFromMeters(speed)) / s") + let time = data.endDate.timeIntervalSinceDate(data.startDate) + let speed = distance / time + print("Speed: \(lengthFormatter.stringFromMeters(speed)) / s") + } } }) ~~~ @@ -109,8 +111,8 @@ import CoreMotion let altimeter = CMAltimeter() if CMAltimeter.isRelativeAltitudeAvailable() { altimeter.startRelativeAltitudeUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: { data, error in - if !error { - println("Relative Altitude: \(data.relativeAltitude)") + if let data = data { + print("Relative Altitude: \(data.relativeAltitude)") } }) } @@ -124,10 +126,9 @@ if CMAltimeter.isRelativeAltitudeAvailable() { import CoreLocation class LocationManagerDelegate: NSObject, CLLocationManagerDelegate { - func locationManager(manager: CLLocationManager!, didUpdateLocations locations: AnyObject[]!) { - let location: CLLocation? = locations[0] as? CLLocation - if let floor: CLFloor? = location?.floor { - println("Current Floor: \(floor?.level)") + func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + if let floor = locations.first?.floor { + print("Current Floor: \(floor.level)") } } } @@ -148,28 +149,28 @@ The following example shows how statistics summed over the duration of the day c ~~~{swift} import HealthKit -let collection: HKStatisticsCollection? = ... -let statistics: HKStatistics? = collection!.statisticsForDate(NSDate()) -for item: AnyObject in statistics!.sources { - if let source = item as? HKSource { - if let quantity: HKQuantity = statistics!.sumQuantityForSource(source) { - if quantity.isCompatibleWithUnit(HKUnit.gramUnitWithMetricPrefix(.Kilo)) { - let massFormatter = NSMassFormatter() - let kilograms = quantity.doubleValueForUnit(HKUnit.gramUnitWithMetricPrefix(.Kilo)) - println(massFormatter.stringFromKilograms(kilograms)) - } - - if quantity.isCompatibleWithUnit(HKUnit.meterUnit()) { - let lengthFormatter = NSLengthFormatter() - let meters = quantity.doubleValueForUnit(HKUnit.meterUnit()) - println(lengthFormatter.stringFromMeters(meters)) - } - - if quantity.isCompatibleWithUnit(HKUnit.jouleUnit()) { - let energyFormatter = NSEnergyFormatter() - let joules = quantity.doubleValueForUnit(HKUnit.jouleUnit()) - println(energyFormatter.stringFromJoules(joules)) - } +let collection: HKStatisticsCollection? = nil//... +let statistics: HKStatistics? = collection?.statisticsForDate(NSDate()) +let sources: [HKSource] = statistics?.sources ?? [] + +for source in sources { + if let quantity: HKQuantity = statistics?.sumQuantityForSource(source) { + if quantity.isCompatibleWithUnit(HKUnit.gramUnitWithMetricPrefix(.Kilo)) { + let massFormatter = NSMassFormatter() + let kilograms = quantity.doubleValueForUnit(HKUnit.gramUnitWithMetricPrefix(.Kilo)) + print(massFormatter.stringFromKilograms(kilograms)) + } + + if quantity.isCompatibleWithUnit(HKUnit.meterUnit()) { + let lengthFormatter = NSLengthFormatter() + let meters = quantity.doubleValueForUnit(HKUnit.meterUnit()) + print(lengthFormatter.stringFromMeters(meters)) + } + + if quantity.isCompatibleWithUnit(HKUnit.jouleUnit()) { + let energyFormatter = NSEnergyFormatter() + let joules = quantity.doubleValueForUnit(HKUnit.jouleUnit()) + print(energyFormatter.stringFromJoules(joules)) } } } @@ -196,8 +197,8 @@ NSStream.getStreamsToHostWithName("nshipster.com", Also filed under: "small but solid fixes", is this convenience method for `NSString`: ~~~{swift} -let string: NSString = "Café" -let substring: NSString = "É" +let string: String = "Café" +let substring: String = "É" string.localizedCaseInsensitiveContainsString(substring) // true ~~~ @@ -245,12 +246,13 @@ The Foundation URL Loading System has remained relatively unchanged since last y import Foundation let session = NSURLSession() -let task = session.dataTaskWithURL(NSURL(string: "http://nshipster.com"), completionHandler: { data, response, error in +let task = session.dataTaskWithURL(NSURL(string: "http://nshipster.com")!, completionHandler: { data, response, error in // ... }) let protectionSpace = NSURLProtectionSpace() -NSURLCredentialStorage.getCredentialsForProtectionSpace(protectionSpace: protectionSpace, task: task, completionHandler: { credentials in +let credentialStorage = NSURLCredentialStorage() +credentialStorage.getCredentialsForProtectionSpace(protectionSpace, task: task, completionHandler: { credentials in // ... }) ~~~ @@ -317,7 +319,7 @@ let configuration = WKWebViewConfiguration() configuration.preferences = preferences let webView = WKWebView(frame: self.view.bounds, configuration: configuration) -let request = NSURLRequest(URL: NSURL(string: "http://nshipster.com")) +let request = NSURLRequest(URL: NSURL(string: "http://nshipster.com")!) webView.loadRequest(request) ~~~ From c7f9e86f6bf99f1f409d8bd3e5b1bfeed8e07a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20W=C3=BCnsch?= Date: Mon, 14 Sep 2015 10:26:31 +0200 Subject: [PATCH 4/5] Fixed example for localization Just translating words isn't enough. The resulting strings are still not correctly localized, but that's a problem with setLocalizedDateFormatFromTemplate itself. Correct would be "23. Juni 2015, 16:56", but that would require changing the template from "yyyyMMMMddhhmm" to "yyyyMMMMddHHmm". --- 2015-06-22-ios9.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/2015-06-22-ios9.md b/2015-06-22-ios9.md index 8e143072..68e1975f 100644 --- a/2015-06-22-ios9.md +++ b/2015-06-22-ios9.md @@ -206,8 +206,12 @@ shortFormatter.stringFromDate(now) fullFormatter.locale = NSLocale(localeIdentifier: "de_DE") shortFormatter.locale = NSLocale(localeIdentifier: "de_DE") +// set the date formats again, because other languages use different formats +fullFormatter.setLocalizedDateFormatFromTemplate("yyyyMMMMddhhmm") +shortFormatter.setLocalizedDateFormatFromTemplate("yyMMMM") + fullFormatter.stringFromDate(now) -// "Juni 23, 2015, 4:56 nachm." +// "23. Juni 2015, 4:56 nachm." shortFormatter.stringFromDate(now) // "Juni 15" ``` From 9fb42ea70089014ee5ef4a2e808989043d6452b0 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Tue, 15 Sep 2015 00:18:23 -0500 Subject: [PATCH 5/5] Minor edits --- 2013-08-19-nshashtable-and-nsmaptable.md | 19 ++++++-- 2013-09-23-ios7.md | 7 +-- 2014-06-09-ios8.md | 59 ++++++++++++++++++------ 2014-11-03-uisplitviewcontroller.md | 14 ++---- 4 files changed, 65 insertions(+), 34 deletions(-) diff --git a/2013-08-19-nshashtable-and-nsmaptable.md b/2013-08-19-nshashtable-and-nsmaptable.md index 6aba6254..bfa338b7 100644 --- a/2013-08-19-nshashtable-and-nsmaptable.md +++ b/2013-08-19-nshashtable-and-nsmaptable.md @@ -35,9 +35,8 @@ hashTable.addObject("foo") hashTable.addObject("bar") hashTable.addObject(42) hashTable.removeObject("bar") -print(hashTable.allObjects) +print("Members: \(hashTable.allObjects)") ~~~ - ~~~{objective-c} NSHashTable *hashTable = [NSHashTable hashTableWithOptions:NSPointerFunctionsCopyIn]; [hashTable addObject:@"foo"]; @@ -65,6 +64,8 @@ NSLog(@"Members: %@", [hashTable allObjects]); - `NSMapTable` can `copy` its values on input. - `NSMapTable` can contain arbitrary pointers, and use pointer identity for equality and hashing checks. +> *Note:* `NSMapTable`'s focus on strong and weak references means that Swift's prevalent value types are a no go—reference types only, please. + ### Usage Instances where one might use `NSMapTable` include non-copyable keys and storing weak references to keyed delegates or another kind of weak object. @@ -72,10 +73,10 @@ Instances where one might use `NSMapTable` include non-copyable keys and storing ~~~{swift} let delegate: AnyObject = ... let mapTable = NSMapTable(keyOptions: .StrongMemory, valueOptions: .WeakMemory) + mapTable.setObject(delegate, forKey: "foo") print("Keys: \(mapTable.keyEnumerator().allObjects)") ~~~ - ~~~{objective-c} id delegate = ...; NSMapTable *mapTable = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory @@ -105,7 +106,11 @@ extension NSMapTable { } set { - setObject(newValue, forKey: key) + if newValue != nil { + setObject(newValue, forKey: key) + } else { + removeObjectForKey(key) + } } } } @@ -121,7 +126,11 @@ extension NSMapTable { - (void)setObject:(id)obj forKeyedSubscript:(id)key { - [self setObject:obj forKey:key]; + if (obj != nil) { + [self setObject:obj forKey:key]; + } else { + [self removeObjectForKey:key]; + } } @end diff --git a/2013-09-23-ios7.md b/2013-09-23-ios7.md index 1d7e106a..3c7244a0 100644 --- a/2013-09-23-ios7.md +++ b/2013-09-23-ios7.md @@ -292,12 +292,7 @@ Even though the number of people who have actually read something saved for late import SafariServices let url = NSURL(string: "http://nshipster.com/ios7")! -do { - try SSReadingList.defaultReadingList()?.addReadingListItemWithURL(url, title: "NSHipster", - previewText: "...") -} catch let error { - print("Error: \(error)") -} +try? SSReadingList.defaultReadingList()?.addReadingListItemWithURL(url, title: "NSHipster", previewText: "...") ~~~ ~~~{objective-c} diff --git a/2014-06-09-ios8.md b/2014-06-09-ios8.md index 74f80ab0..1b670635 100644 --- a/2014-06-09-ios8.md +++ b/2014-06-09-ios8.md @@ -86,7 +86,7 @@ import CoreMotion let lengthFormatter = NSLengthFormatter() let pedometer = CMPedometer() -pedometer.startPedometerUpdatesFromDate(NSDate(), withHandler: { data, error in +pedometer.startPedometerUpdatesFromDate(NSDate()) { data, error in if let data = data { print("Steps Taken: \(data.numberOfSteps)") @@ -98,7 +98,7 @@ pedometer.startPedometerUpdatesFromDate(NSDate(), withHandler: { data, error in print("Speed: \(lengthFormatter.stringFromMeters(speed)) / s") } } -}) +} ~~~ ## CMAltimeter @@ -110,11 +110,11 @@ import CoreMotion let altimeter = CMAltimeter() if CMAltimeter.isRelativeAltitudeAvailable() { - altimeter.startRelativeAltitudeUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: { data, error in + altimeter.startRelativeAltitudeUpdatesToQueue(NSOperationQueue.mainQueue()) { data, error in if let data = data { print("Relative Altitude: \(data.relativeAltitude)") } - }) + } } ~~~ @@ -149,12 +149,12 @@ The following example shows how statistics summed over the duration of the day c ~~~{swift} import HealthKit -let collection: HKStatisticsCollection? = nil//... +let collection: HKStatisticsCollection? = ... let statistics: HKStatistics? = collection?.statisticsForDate(NSDate()) let sources: [HKSource] = statistics?.sources ?? [] for source in sources { - if let quantity: HKQuantity = statistics?.sumQuantityForSource(source) { + if let quantity = statistics?.sumQuantityForSource(source) { if quantity.isCompatibleWithUnit(HKUnit.gramUnitWithMetricPrefix(.Kilo)) { let massFormatter = NSMassFormatter() let kilograms = quantity.doubleValueForUnit(HKUnit.gramUnitWithMetricPrefix(.Kilo)) @@ -194,11 +194,11 @@ NSStream.getStreamsToHostWithName("nshipster.com", ## NSString -localizedCaseInsensitiveContainsString -Also filed under: "small but solid fixes", is this convenience method for `NSString`: +Also filed under: "small but solid fixes", is this convenience method for `String`/`NSString`: ~~~{swift} -let string: String = "Café" -let substring: String = "É" +let string = "Café" +let substring = "É" string.localizedCaseInsensitiveContainsString(substring) // true ~~~ @@ -246,15 +246,15 @@ The Foundation URL Loading System has remained relatively unchanged since last y import Foundation let session = NSURLSession() -let task = session.dataTaskWithURL(NSURL(string: "http://nshipster.com")!, completionHandler: { data, response, error in +let task = session.dataTaskWithURL(NSURL(string: "http://nshipster.com")!) { data, response, error in // ... -}) +} let protectionSpace = NSURLProtectionSpace() let credentialStorage = NSURLCredentialStorage() -credentialStorage.getCredentialsForProtectionSpace(protectionSpace, task: task, completionHandler: { credentials in +credentialStorage.getCredentialsForProtectionSpace(protectionSpace, task: task) { credentials in // ... -}) +} ~~~ ## kUTTypeToDoItem @@ -275,6 +275,23 @@ Most users are completely unaware that most pictures taken with phones these day New to the Image I/O framework is a convenient new option for `CGImageDestination`: `kCGImageMetadataShouldExcludeGPS`, which does what you'd expect. +~~~{swift} +import UIKit +import ImageIO +import MobileCoreServices + +let image = ... +let fileURL = NSURL(fileURLWithPath: "/path/to/output.jpg") +let options: NSDictionary = [kCGImageDestinationLossyCompressionQuality as NSString: 0.75, + kCGImageMetadataShouldExcludeGPS as NSString: true] + +if let imageDestination = CGImageDestinationCreateWithURL(fileURL, kUTTypeJPEG, 1, nil), + let cgImage = image.CGImage +{ + CGImageDestinationAddImage(imageDestination, cgImage, options) + CGImageDestinationFinalize(imageDestination) +} +~~~ ~~~{objective-c} @import UIKit; @import ImageIO; @@ -346,6 +363,22 @@ Imagine: with CloudKit and LocalAuthentication, nearly all of the friction to cr LocalAuthentication works in terms of an `LAContext` class, which evaluates a specified policy, and gives a thumbs up or thumbs down on user authentication. At no point is any biometric information made available to the application—everything is kept safe on the hardware itself. +~~~{swift} +let context = LAContext() +var error: NSError? + +if context.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: &error) { + context.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "...") { success, error in + if success { + // ... + } else { + print("Error: \(error)") + } + } +} else { + print("Error: \(error)") +} +~~~ ~~~{objective-c} LAContext *context = [[LAContext alloc] init]; NSError *error = nil; diff --git a/2014-11-03-uisplitviewcontroller.md b/2014-11-03-uisplitviewcontroller.md index 2c4ef0a2..9d993a86 100644 --- a/2014-11-03-uisplitviewcontroller.md +++ b/2014-11-03-uisplitviewcontroller.md @@ -82,7 +82,6 @@ override func viewDidLoad() { navigationItem.leftItemsSupplementBackButton = true } ~~~ - ~~~{objective-c} - (void)viewDidLoad { [super viewDidLoad]; @@ -111,13 +110,9 @@ There is one more optimization we can do for the iPhone 6+ via [`UISplitViewCont When the user first launches the app, we can make the master view controller fully displayed until the user selects a list item: ~~~{swift} -import UIKit - class SelectColorTableViewController: UITableViewController, UISplitViewControllerDelegate { private var collapseDetailViewController = true - // MARK: UITableViewController - override func viewDidLoad() { super.viewDidLoad() @@ -126,7 +121,7 @@ class SelectColorTableViewController: UITableViewController, UISplitViewControll // ... - // MARK: UITableViewDelegate + // MARK: - UITableViewDelegate override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { collapseDetailViewController = false @@ -139,13 +134,14 @@ class SelectColorTableViewController: UITableViewController, UISplitViewControll } } ~~~ - ~~~{objective-c} -@import UIKit; +// SelectColorTableViewController.h @interface SelectColorTableViewController : UITableViewController @end +// SelectColorTableViewController.m + @interface SelectColorTableViewController () @property (nonatomic) BOOL shouldCollapseDetailViewController; @@ -154,8 +150,6 @@ class SelectColorTableViewController: UITableViewController, UISplitViewControll @implementation SelectColorTableViewController -#pragma mark - UITableViewController - - (void)viewDidLoad { [super viewDidLoad];