I am new to Swift and I am trying to understand how could a class get a value inside an extension.
I have two problems but they are similar to each other, but first I will explain my project. I am using 2 controllers (MainViewController and…
In Objective-C, one should always prefix category methods, e.g. if extending UIView with the method descendants, you'd add zzz_ and make it zzz_descendants to avoid naming conflicts. Is that necessary for a function in extension UIView { ... } in…
Consider this case, a variable declared in an extension, like this.
extension UIViewController {
var apiClient: APIClient {
return APIClientImplementation()
}
}
Does this extension return a new instance each time i call it from a…
I was reading open source project and I found extension for a specific view controller like :
import UIKit
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
…
I want to have a default property of UIImageView, which would be isFlipped. I am able to do it by subclassing UIImageView and adding one property isFlipped.
But I want to user protocol and extensions for this , but it is crashing after sometime.…
I have one extension which helps me to range bound a value with min and max. There are different scenarios where I need to use a different type like Int, Float, Double, CGFloat. So for that, I have created multiple extensions like below.
extension…
I am creating a UIView or a UIToolbar for my keyboard when I select a textfield.
For example something like that in my viewDidLoad:
let customView = UIView(frame: CGRectMake(0, 0, self.view.frame.size.width, 40))
customView.backgroundColor =…
Using Xcode 8 beta, swift 3 the second extension can not compiled. I don't understand if this is a swift bug or a known limitation.
extension Array {
func scanl(initial: T, combine:(Iterator.Element, T) -> T) -> [T] {
guard let first…
I'm trying to unwrap dictionary in extension as Dictionary.
But I'm having some problems and can't find answer anywhere.
I have a function which gets a dictionary, where inside I want to get a json string from JSON dictionary, of course if it is a…
I try to add SlideMenuControllerSwift in Objective-c.
I can access [slideMenuController openLeft] in my AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *sb…
I would like to override a method that is declared in a framework and implemented in an extension.
Here's what I've tried :
import UIKit
// Code from a dependency
class Object { // UIViewController
func printSomething() {
…
Is there a way to count the number of UIView instances created on UI without changing too much code? I need to improve performance, I feel some of the UIView instances are untracked.
Is there a way to create an extension of UIView and always return…
Here is the map method which seems to be duplicate in Sequence protocol. How is apple doing this? what is the intention behind this?
public protocol Sequence {
public func map(_ transform: (Self.Iterator.Element) throws -> T) rethrows ->…
I am replacing some Obj-C in an app where there is a category on NSDictionary and I need the same functionality in a Swift extension. I have written the extension and have a clean build, however when trying to use the extension my parameter type is…
Is it possible for a computed property in extension to have both getter and setter? Apple's guide does not mention it and the only example I have seen only shows read-only computed property in extension.