Files
swift-mirror/stdlib/core/ObjCMirrors.swift
Dave Abrahams 94965036d5 [stdlib] Move ObjC Mirrors out of Foundation
These mirrors are the default mirrors that get used for all objective-C
object, including some that aren't defined in Foundation:

  import Dispatch
  println(dispatch_get_global_queue(0,0))

This example isn't fixed yet, because we need to pull all the string
bridging goop out of Foundation and into the core standard library.

Swift SVN r25012
2015-02-05 19:18:33 +00:00

78 lines
2.4 KiB
Swift

//===--- ObjCMirrors.swift ------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#if _runtime(_ObjC)
@asmname("swift_ObjCMirror_count")
func _getObjCCount(_MagicMirrorData) -> Int
@asmname("swift_ObjCMirror_subscript")
func _getObjCChild(Int, _MagicMirrorData) -> (String, MirrorType)
@objc protocol _DebugDescriptionProxy {
var debugDescription: _CocoaStringType {get}
}
func _getObjCSummary(data: _MagicMirrorData) -> String {
let theObject = data._loadValue() as _DebugDescriptionProxy
return _cocoaStringToSwiftString_NonASCII(theObject.debugDescription)
}
public // SPI(runtime)
struct _ObjCMirror: MirrorType {
let data: _MagicMirrorData
public var value: Any { return data.objcValue }
public var valueType: Any.Type { return data.objcValueType }
public var objectIdentifier: ObjectIdentifier? {
return data._loadValue() as ObjectIdentifier
}
public var count: Int {
return _getObjCCount(data)
}
public subscript(i: Int) -> (String, MirrorType) {
return _getObjCChild(i, data)
}
public var summary: String {
return _getObjCSummary(data)
}
public var quickLookObject: QuickLookObject? {
return _getClassQuickLookObject(data)
}
public var disposition: MirrorDisposition { return .ObjCObject }
}
public // SPI(runtime)
struct _ObjCSuperMirror: MirrorType {
let data: _MagicMirrorData
public var value: Any { return data.objcValue }
public var valueType: Any.Type { return data.objcValueType }
// Suppress the value identifier for super mirrors.
public var objectIdentifier: ObjectIdentifier? {
return nil
}
public var count: Int {
return _getObjCCount(data)
}
public subscript(i: Int) -> (String, MirrorType) {
return _getObjCChild(i, data)
}
public var summary: String {
return _getObjCSummary(data)
}
public var quickLookObject: QuickLookObject? {
return _getClassQuickLookObject(data)
}
public var disposition: MirrorDisposition { return .ObjCObject }
}
#endif