I'm following the tutorial here to display GIF image on UIImage. I have write the extension UIImage+GIF.swift which basically like this:
extension UIImage {
public class func gifImage(named: String) -> UIImage {
...
}
}
along with…
I want to define a extension to Array (or Sequence or Collector?) so I can query a list of lists of a custom object with a NSIndexPath and get the object based on the indexPath's section and row.
public var tableViewData = [[MyCellData]]() //…
I have been on this for awhile now and no matter what I look up I can't seem to understand this. Suppose I'm extending UIView to add a toolbar on keyboard, I am not entirely sure how to pass parameters I need to access from the class that is using…
How can I compactly write an extension of an Array in Swift 3.0 which works for both Float and Double Element types?
The following doesn't work:
extension Array where Element: FloatingPoint
{
public func multiply(mult: Double) -> [Double] {
…
In the context of this question, I though about how one could implement a property or method that counts across all nesting levels in collections.
Intuitively, something this should work:
extension Collection {
var flatCount: Int {
if…
The question refers to Swift3.
Since version 4 you can finally cast objects to Type like this:
someObject as (Type & Protocol)
I have a protocol and multiple types inheriting from it.
A, B, C, D: CKEntity (pseudocode)
For that protocol…
I'm trying to build a protocol exposing a static property, then use that static property in an extension of that protocol, but it seems to work only if I define this static property in the protocol extension as well.
Basically the code I'm trying to…
When I try and add swift extensions to classes in XcodeKit (framework for adding Xcode extensions) the compiler is happy to build without any errors, but when the code runs I get the following exception:
-[XCSourceEditorCommandInvocation test]:…
I am attempting to add an extension to the Array type in Swift limited to Arrays whose elements conform to the equatable protocol. I am attempting to define a function in the following manner:
import Foundation
extension Array where…
I have a protocol as well as a protocol extension and I'd like to implement a function in the protocol extension to sort an array defined by the protocol with custom objects, but it's not working.
protocol MyProtocol {
var myArray: [MyObject] {…
I have a custom protocol with which I have extended some structures in Swift.
Code example:
protocol someprotocol {
func foo() -> Int
}
extension Int : someprotocol {
func foo() {
return 4
}
}
I do this with many structs like int8,…
I am adding functionality to an AWS class that creates a singleton (AWSIdentityManager) and the code for that class is in flux (AWS are improving it). I would like to make my added functionality more distinct from the AWS code so that I don't have…
I'd like to share some really useful swift extensions that I built for my apps. I'm sure there are many developers that are looking to easily add the custom functionality to their apps. The only issue is I can't find a good way to share these…
I can't find the syntax, but I want to do something like this:
class MyClass {
let stringValue: String // filled in later
let integerValue: Int // filled in later
init(stringValue: String) {
self.stringValue = stringValue
…
protocol(myProtocol):-
protocol myProtocol {
var type:String { get set }
var sub:String { get }
var msg:String? { get set }
}
Class(myVC):-
class myVC: UIViewController, myProtocol {
//Protocol Declarations
var…