Questions tagged [swift-extensions]

Extensions add new functionality to an existing class, structure, or enumeration type.

Apple Pre-release Docs

394 questions
0
votes
3 answers

Swift Array of dictionaries extension sortInPlace

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,…
0
votes
1 answer

Can't invoke protocol method on generic type restricted by other protocol

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) } …
user2320861
  • 1,391
  • 2
  • 11
  • 28
0
votes
1 answer

How can I create an extension with a function which creates a UIView which can be placed at different positions?

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…
pogbamessi
  • 311
  • 3
  • 17
0
votes
1 answer

Extension for CollectionType with element of certain type ignores subtypes

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 =…
Henrik Lineholm
  • 356
  • 1
  • 6
  • 9
0
votes
1 answer

Extension with a receive value

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)"…
LettersBa
  • 747
  • 1
  • 8
  • 27
0
votes
2 answers

static protocol extensions generates Illegal Instruction compiler error

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…
Johnathon Sullinger
  • 7,097
  • 5
  • 37
  • 102
0
votes
1 answer

Swift extension for getting instance private property

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…
Adam Bardon
  • 3,829
  • 7
  • 38
  • 73
0
votes
2 answers

Calling delegate method from Swift's Extension class

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.
Gopal Devra
  • 564
  • 2
  • 5
  • 24
0
votes
2 answers

Swift Extension Class Function only works in 1 file

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.…
MLyck
  • 4,959
  • 13
  • 43
  • 74
0
votes
1 answer

Does not have a member named ( Swift )

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…
0
votes
1 answer

Converation from array of Bytes to Struct. Swift

I have dump of bytes and i need to parse structures c++ exmpl: (*(SomeStruct*)(bufPtr)) how can i do it on swift?
t0me0
  • 13
  • 1
0
votes
1 answer

Swift extension on NSManagedObject

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…
Louie Bertoncin
  • 3,744
  • 2
  • 25
  • 28
0
votes
1 answer

Orientation change in Swift height change and uibutton hide on landscape

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…
user3151224
-1
votes
0 answers

How to call method, or method on extension that has generic type constraints?

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)…
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
-1
votes
2 answers

Can a class inherit convenience inits even if there is designated inits

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} …
xarly
  • 2,054
  • 4
  • 24
  • 40