I've been playing around with Generics and Extensions to existing types in Swift 3. I wrote two generic Array functions that extends Array with find-and-replace methods, named replaced() and replace(). The replaced() function works as intended but…
I made an extension that lets me resize a UIImage but I'm wondering if I'm calling it correctly. The extension is in it's own file and is like this:
extension UIImage {
func resizeImage(image: UIImage, targetSize: CGSize) -> UIImage {
…
I have looked at many examples of extensions, thought can't find this. I am simply trying to use extension to add a toolbar with buttons on top of keyboard in swift, but since extensions can't have stored values easily , is there a simple way to…
Instead of assigning the view controller as the UITableViewDelegate, I'm trying to reduce the code in the view controller by creating an extension for the UITableViewDelegate.
Why am I getting the error "Use of unresolved identifier…
Say I want to extend nested dictionaries with some functionality. Using pseudo-Swift, this is my goal:
extension Dictionary where Value: Dictionary {
typealias K1 = Key
typealias K2 = Value.Key
typealias V = Value.Value
…
I've tried the solution in extension of Dictionary where but it won't compile for me.
I simply want to constrain a dictionary extension to struct types. Is there any way of accomplishing this?
import Cocoa
struct Foo: Hashable…
If I have an instance of UILabel in storyboard and I have it connected to view controller as IBOutlet. If I want add some functionality only to this label, how can I do it? I know that for obj-c you make a subclass of UILabel. But I wonder if there…
Hi I'm trying to retrieve data by using ParseLiveQuery
My problem is...I can't assign the item in Array..
import Foundation
import Parse
import ParseLiveQuery
extension _ArrayProtocol where Iterator.Element == PFObject {
mutating func…
I have a function that converts minutes to either a decimal or a HH:MM string based on a user preference in NSUserDefaults.
For example, 90 minutes would be either 1.5 or 1:30.
Here's my function:
func decimalOrHHMM(value:Int) -> String{
let…
Okay so I have an error with my extension, which whenever I add a line or space it up it creates more errors with the UIColor. I can use the Clean function to get it back down to these two errors. My extension is not in {} and I think I have all my…
I'm trying to use a random number extension I created that worked in swift 2 and fails in Swift 3. Not sure why.
Here is the code.
let aRandomInt = Int.random(range:0...2)
//Extention to INT to create random number in range.
extension Int
{
…
I am trying to create a Type extension for UIColor per the code snippet below, but I'm receiving a build error. When I try to create the UIColor object in my Type extension method, the UIColor constructor is referencing the encapsulating UIColor…
I have created an extension for UIColor in swift to add custom colors. The colors I have grouped together in their own namespace for which I have used enums with no cases. Here is the class:
extension UIColor {
public enum FirstGroup {
…
I'm trying to write an extension method on UIView that will be called whenever a view is initialized, meaning that the method should be invoked without my having to call on it explicitly. Is there a way to accomplish this such as with key-value…
In my extension I put the control for the keyboard notification in this way
protocol KeyboardSpaceProtocol {
func addObservers()
func removeObservers()
func keyboardWillShow(notification:NSNotification) -> CGFloat
}
extension UIView:…