Custom UITableViewCell from nib in Swift

With Swift 5 and iOS 12.2, you should try the following code in order to solve your problem: CustomCell.swift import UIKit class CustomCell: UITableViewCell { // Link those IBOutlets with the UILabels in your .XIB file @IBOutlet weak var middleLabel: UILabel! @IBOutlet weak var leftLabel: UILabel! @IBOutlet weak var rightLabel: UILabel! } TableViewController.swift import UIKit … Read more

WKWebView not loading local files under iOS 8

They finally solved the bug! Now we can use -[WKWebView loadFileURL:allowingReadAccessToURL:]. Apparently the fix was worth some seconds in WWDC 2015 video 504 Introducing Safari View Controller For iOS8 ~ iOS10 (Swift 3) As Dan Fabulish’s answer states this is a bug of WKWebView which apparently is not being solved any time soon and as … Read more

Communicating and persisting data between apps with App Groups

Another benefit to App Groups is the ability to share a NSUserDefaults database. This also works for App Extensions (notification center widgets, custom keyboards, etc). Initialize your NSUserDefaults object like this in all applications in the app group and they will share the database: Objective-C: [[NSUserDefaults alloc] initWithSuiteName:@”<group identifier>”]; Swift: NSUserDefaults(suiteName: “<group identifier>”) Keep in … Read more

Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?

Yes, it’s orientation-dependent in iOS8, not a bug. You could review session 214 from WWDC 2014 for more info: “View Controller Advancements in iOS 8” Quote from the presentation: UIScreen is now interface oriented: [UIScreen bounds] now interface-oriented [UIScreen applicationFrame] now interface-oriented Status bar frame notifications are interface-oriented Keyboard frame notifications are interface-oriented

Can I set the cookies to be used by a WKWebView?

Edit for iOS 11+ only Use WKHTTPCookieStore: let cookie = HTTPCookie(properties: [ .domain: “example.com”, .path: “https://stackoverflow.com/”, .name: “MyCookieName”, .value: “MyCookieValue”, .secure: “TRUE”, .expires: NSDate(timeIntervalSinceNow: 31556926) ])! webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie) Since you are pulling them over from HTTPCookeStorage, you can do this: let cookies = HTTPCookieStorage.shared.cookies ?? [] for cookie in cookies { webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie) } Old answer for … Read more

How to force view controller orientation in iOS 8?

For iOS 7 – 10: Objective-C: [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) forKey:@”orientation”]; [UINavigationController attemptRotationToDeviceOrientation]; Swift 3: let value = UIInterfaceOrientation.landscapeLeft.rawValue UIDevice.current.setValue(value, forKey: “orientation”) UINavigationController.attemptRotationToDeviceOrientation() Just call it in – viewDidAppear: of the presented view controller.