How to convert NSURL to String in Swift

It turns out there are properties of NSURL you can access (see Swift Reference): var directoryURL: NSURL var urlString: String = directoryURL.absoluteString // OR var urlString: String = directoryURL.relativeString // OR var urlString: String = directoryURL.relativePath // OR var urlString: String = directoryURL.path // etc.

Converting Int to Bool

No, there is and has never been an explicit built in option for conversion of Int to Bool, see the language reference for Bool for details. There exists, still, however, an initializer by NSNumber. The difference is that implicit bridging between Swift numeric type and NSNumber has been removed in Swift 3 (which previously allowed … Read more

How do I use UserDefaults with SwiftUI?

The approach from caram is in general ok but there are so many problems with the code that SmushyTaco did not get it work. Below you will find an “Out of the Box” working solution. 1. UserDefaults propertyWrapper import Foundation import Combine @propertyWrapper struct UserDefault<T> { let key: String let defaultValue: T init(_ key: String, … Read more

Increase the size of the indicator in UIPageViewController’s UIPageControl

Scaling the page control will scale the dots, but will also scale the spacing in between them. pageControl.transform = CGAffineTransform(scaleX: 2, y: 2) If you want to keep the same spacing between dots, you’ll need to transform the dots individually: pageControl.subviews.forEach { $0.transform = CGAffineTransform(scaleX: 2, y: 2) } However, if you do this in … Read more

Storyboard Entry Point Missing

Click on Top of ViewController or Controller in Document Outline window (on left side) of the Controller you want to make Storyboard Entry Point. Click on Attribute inspector button (in right side). Enable “Is Initial View Controller”. Storyboard Entry Point will reappear hopefully.

How to add initializers in extensions to existing UIKit classes such as UIColor?

You can’t do it like this, you have to chose different parameter names to create your own initializers/ You can also make them generic to accept any BinaryInteger or BinaryFloatingPoint types: extension UIColor { convenience init<T: BinaryInteger>(r: T, g: T, b: T, a: T = 255) { self.init(red: .init(r)/255, green: .init(g)/255, blue: .init(b)/255, alpha: .init(a)/255) … Read more

New @convention(c) in Swift 2: How can I use it?

Passing a Swift closure to a C function taking a function pointer parameter is now supported in Swift 2, and, as you noticed, function types are specified with the @convention(c) attribute. If you pass a closure directly as an argument to the C function then this attribute is inferred automatically. As a simple example, if … Read more