I have an extension of NSURLSessionDownloadTask, inside of this Extension, I created a stored property called 'id' using Objective C Associated Objects. When I try to set the property, I get 'an unrecognized selector sent to instance'. Here's my…
I'm trying to override an instance method from a protocol extension, and I'm having some trouble.
For context, I'm making an iOS app with a lot of different UICollectionViews. These views get data from different databases (requiring different…
In Swift 3, say there is a system defined enum (i.e. I don't control the source code) like this:
enum currentState: Int {
case enabled
case disabled
case unknown
}
Is it possible to add an associated value to the existing members specifically…
My project is a mix of Obj-C and Swift, and I'm trying to extend my AppDelegate class with Swift.
So right now I have AppDelegate.m, AppDelegate.h, and AppDelegate.swift. Most of the methods are in the Obj-C file, but I'm trying to implement just…
I'm trying to write an extension to Array in Xcode's playground. I want to write a function that will modify the array so that it will be filled with 0s when the function is called. The code I'm attempting to use is this:
import…
How can you view the full API for a class including any defined extensions?
If you open the class in Xcode and view the method list in the quick jump bar it doesn't include any methods defined in any existing extensions for that class.
Ie: You…
I'd like to create an extension off all types that have the .contains API.
For example, I did this for strings, but would like to expand it for all types:
func within(values: [String]) -> Bool {
return values.contains(self)
}
With this, instead…
For fun, I am attempting to extend the Dictionary class to replicate Python's Counter class. I am trying to implement init, taking a CollectionType as the sole argument. However, Swift does not allow this because of CollectionType's associated…
I'm trying to build a simple observer mixin with Swift 2.
Here comes just the relevant part.
protocol Observable{
typealias T
var observers:[T] { get set }
mutating func removeObserver(observer:T)
}
To create the mixin I use an…
I do a bunch of work with [Uint8] arrays. But I often have to recast these as NSData objects to interface with iOS frameworks such as CoreBluetooth. So I have lots of code that might look something like:
var input:[UInt8] = [0x60, 0x0D, 0xF0,…
I think my cognition for Swift types/protocols/generics has overflowed. I've been using the pattern of extending "an input stream bytes" by doing something like:
extension GeneratorType where Element == UInt8 {
func foobar() {
...
…
I have Cocoapod library that offers its functionality via an extension like this:
extension ExposedLibraryClass
{
class func setup () { ... }
}
I have some boilerplate code that goes into setup() for every app I do, but each app also needs some…
I've been trying to make abstract superclass-like behaviour in Swift using the protocols and extensions suggested here: Abstract classes in Swift Language
But I can't figure out how to write methods that make use of static (class) variables. For…
I have a string extension in which I define a function that calculates the DamerauLevenshtein distance between two different strings. When adding the following code:
var result = "Hello"
result.damerauLevenshteinTo("Hellow")
in any other class…