I am trying to write an extension for this:
extension [String : AnyObject] {
}
It throws and error. I was also trying to come up with something similar as this:
extension Dictionary: [String : AnyObject] {
}
It also fails.
Is there a solution…
Say we are in an instance of SomeClass, consider this simple call
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: #selector(SomeClass.fixer(_:)),
name:"FixerNote",
object:nil)
Say we decide to make an extension to save typing,…
I have a protocol called NakedNavigationBar.
I also have an extension that extends all UIViewControllers that conform to NakedNavigationBar.
The problem is that in the extension I want to add default behaviour so that when the UIViewController…
I'm trying to create a protocol that wraps the process of using the UIImagePickerController to make it more stream-lined in my apps. I essentially have something like this:
public protocol MediaAccessor : UIImagePickerControllerDelegate,…
I'm trying to write default behaviour for a delegate method using a Swift extension as below, but it is never called. Does anyone know why or how to do it the right way?
extension NSURLSessionDelegate {
public func URLSession(session:…
I would like to add an extension on Dictionary that only applies to a dictionary with Strings as Keys and Array of NSManagedObject as Value
Ideally it would look like this:
extension Dictionary where Key : StringLiteralConvertible, Value:…
For Swift fun, I thought I'd build out some alternate reified APIs to GCD. So I threw this in a Playground:
import Foundation
typealias DispatchQueue = dispatch_queue_t
extension DispatchQueue {
static var main:DispatchQueue {
return…
For instance, I want to extract a Swift protocol from my existing Objective-C class MyFoo. Let's call this protocol FooProtocol.
The situation looks like this:
// In Objective-C
@interface MyFoo
@property(nonatomic, copy) NSString…
I am trying using extension for an existing class with class method like:
@objc public protocol MyProtocol {
optional class func foo() -> Int
}
And I am using this protocol in an extension with generic like:
extension MyClass {
public func…
I am trying to build my understanding of Generics in Swift by creating a Min and Max extension for the Array class (similar to Min and Max Extension methods in C#). There may be a better way to do this, but as I said, it just to help me understand…
I'm playing around with Swift extensions, and bumped my head against a strange bug, while trying to extend Bool:
typealias Task = ()->()
extension Bool{
func untilFalse(task: Task){
while !self {println(self); task()}
}
}
var i =…
Having a strange problem with generics on Swift
have a NSManagedObject subclasses hierarchy with extensions:
BaseCloudKitItem<-MyObject
extension BaseCloudKitItem {
func updateDataWithCKRecord(record: CKRecord!, inManagedObjectContext context:…
After some amount of stress, I created the following generic function:
func removeDupes (inout inputCollection : [T] ) -> [T] {
var hashMap = [T : Bool]()
var output = 0
for thing in inputCollection {
if !hashMap[thing] {
…