Using Swift 2.1 I'm trying to make a function that sorts an array of dictionaries by the date value for the key dateKey.
I want to add this as an extension to the Array type, so I can call it using someArray.sortDictionariesByDate(dateKey: String,…
I have the following:
protocol Guard {
var prisoners: Array? { get set }
func smack(prisoner: T)
func smackAll()
}
extension Guard {
final func smackAll() {
prisoners?.forEach() { smack($0) }
…
I have to create a custom UIView which is actually a circle having the same size and appearance which is placed at different positions in a view. I created an extension which works fine for one circle, but I want to use that same function to place…
I'm trying to create an extension for collection types containing elements of a certain type FooType and this works just fine:
extension CollectionType where Generator.Element == FooClass
{
func doSomething()
}
let collectionType =…
I'm learning about extension in swift and I want to create a extension for String like the command .hasPrefix(), in that command we send a String, for test it I try this code:
extension String{
var teste:(String) { return "\(self) - \($1)"…
I have read up on the Extensions available in Swift and was wondering if static protocol extensions are supported? I know that instance methods can be used in a protocol extension.
I was wanting to create a protocol for my repository, along with an…
I'm using this open source library which is a wrapper on AddressBook.framework. There's no method for deleting contact, so I'm gonna use default ABAddressBookRemoveRecord. However for that I need the ABAddressBookRef.
Since it's declared in…
All
I am implementing a UIAlertView extension for callback implementation like UIAlertView+Block in Objective C but the delegate method is not calling from this class any help.
Thanks in advance.
I have a file called UIElements.swift which contains some extension I want to use throughout my app.
They've worked great so far. Until I created a new viewController, and I can't get any of them to work in that or any other viewControllers I make.…
I have two labels (CountryCode, CountryName) in prototype cells, and I created a class for them called " CountryCell " and I created the TableViewController class called " CountriesVC " I made the labels' outlets in the CountryCell but I want to use…
I could do this in Objective-C, but I'm having trouble figuring out how to make it work in Swift. I'm writing an extension on an NSManagedObject so that I can simply call a function any time I want to create a new entity. The function will then…
I am making one custom keyboard in which when orientation of mobile is changed then in landscape i have to hide one button please suggest how can i do this i am using below code to do this task please help me.
in landscape also the button is visible…
I am trying to do something like this:
public struct FlowHStack: View where Data: RandomAccessCollection, Content: View, ID: Hashable {
let data: Data
let dataId: KeyPath
let content: (Data.Element)…
I've got the following classes:
class A {
let age:Int
init(age: Int) {
self.age = age
}
}
extension A {
convenience init?(ageString: String) {
guard let age = Int(ageString) else { return nil}
…