Skip to content
This repository has been archived by the owner on Jun 11, 2018. It is now read-only.

Commit

Permalink
Add support for Objective-C bridging
Browse files Browse the repository at this point in the history
You still have to opt in to get the bridging support with `extension Foo: _ObjectiveCBridgeable { }` but this supplies the implementation of that protocol for ValueCoding types.
  • Loading branch information
Ryan Arana authored and danthorpe committed Apr 30, 2016
1 parent 9efdd97 commit 9aa7dd0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ValueCoding/ValueCoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ extension CodingType where ValueType: ValueCoding, ValueType.Coder == Self {
}
}

/**
Objective-C bridging support. Allows for use of value types in `NSArray` and company.
*/
extension ValueCoding where Coder: NSCoding, Coder.ValueType == Self {
static func _isBridgedToObjectiveC() -> Bool {
return true
}

static func _getObjectiveCType() -> Any.Type {
return Coder.self
}

static func _forceBridgeFromObjectiveC(source: Coder, inout result: Self?) {
result = source.value
}

static func _conditionallyBridgeFromObjectiveC(source: Coder, inout result: Self?) -> Bool {
result = source.value
return true
}

func _bridgeToObjectiveC() -> Coder {
return encoded
}
}

extension SequenceType where
Generator.Element: CodingType {

Expand Down

0 comments on commit 9aa7dd0

Please sign in to comment.