-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround bridging deficiencies of Swift on Linux
Likely temporary, but currently needed.
- Loading branch information
Showing
4 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Bridging.swift | ||
// Contentful | ||
// | ||
// Created by Boris Bügling on 26/01/16. | ||
// Copyright © 2016 Contentful GmbH. All rights reserved. | ||
// | ||
|
||
/* | ||
This is needed with Swift 2.2 snapshots as of 2016/01/26, probably can go away in the future. | ||
*/ | ||
|
||
import Foundation | ||
|
||
#if os(Linux) | ||
func bridge(any: Any) -> AnyObject { | ||
if let any = any as? [String:Any] { return bridge(any) } | ||
|
||
if let any = any as? [Any] { | ||
let array = NSMutableArray() | ||
any.forEach { array.addObject(bridge($0)) } | ||
return array | ||
} | ||
|
||
if let any = any as? String { return NSString(string: any) } | ||
if let any = any as? Bool { return NSNumber(bool: any) } | ||
if let any = any as? Double { return NSNumber(double: any) } | ||
|
||
fatalError("Could not bridge \(any.dynamicType)") | ||
} | ||
|
||
func bridge(dict: [String:Any]) -> NSDictionary { | ||
let result = NSMutableDictionary() | ||
for (key, obj) in dict { | ||
if let obj = obj as? AnyObject { | ||
result.setObject(obj, forKey: NSString(string: key)) | ||
} else { | ||
result.setObject(bridge(obj), forKey: NSString(string: key)) | ||
} | ||
} | ||
return result | ||
} | ||
|
||
func bridge(array: [NSObject:AnyObject]) -> [String:AnyObject] { | ||
var result = [String:AnyObject]() | ||
for (key, value) in array { | ||
result[key.description] = value | ||
} | ||
return result | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters