Files
swift-mirror/stdlib/public/SDK/UIKit/UIKit.swift
Dmitri Hrybenko dd38372fb7 CMake: build all platforms except watchOS using the public SDK
Covers rdar://problem/21145996.
A step towards rdar://problem/21099318.

Swift SVN r31244
2015-08-14 17:26:04 +00:00

266 lines
7.3 KiB
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
//
//===----------------------------------------------------------------------===//
import Foundation
@exported import UIKit
//===----------------------------------------------------------------------===//
// Equatable types.
//===----------------------------------------------------------------------===//
@transparent // @fragile
@warn_unused_result
public func == (lhs: UIEdgeInsets, rhs: UIEdgeInsets) -> Bool {
return lhs.top == rhs.top &&
lhs.left == rhs.left &&
lhs.bottom == rhs.bottom &&
lhs.right == rhs.right
}
extension UIEdgeInsets : Equatable {}
@transparent // @fragile
@warn_unused_result
public func == (lhs: UIOffset, rhs: UIOffset) -> Bool {
return lhs.horizontal == rhs.horizontal &&
lhs.vertical == rhs.vertical
}
extension UIOffset : Equatable {}
// These are un-imported macros in UIKit.
//===----------------------------------------------------------------------===//
// UIDeviceOrientation
//===----------------------------------------------------------------------===//
#if !os(watchOS) && !os(tvOS)
public extension UIDeviceOrientation {
var isLandscape: Bool {
get { return self == .LandscapeLeft || self == .LandscapeRight }
}
var isPortrait: Bool {
get { return self == .Portrait || self == .PortraitUpsideDown }
}
var isFlat: Bool {
get { return self == .FaceUp || self == .FaceDown }
}
var isValidInterfaceOrientation: Bool {
get {
switch (self) {
case .Portrait, .PortraitUpsideDown, .LandscapeLeft, .LandscapeRight:
return true
default:
return false
}
}
}
}
@warn_unused_result
public func UIDeviceOrientationIsLandscape(
orientation: UIDeviceOrientation
) -> Bool {
return orientation.isLandscape
}
@warn_unused_result
public func UIDeviceOrientationIsPortrait(
orientation: UIDeviceOrientation
) -> Bool {
return orientation.isPortrait
}
@warn_unused_result
public func UIDeviceOrientationIsValidInterfaceOrientation(
orientation: UIDeviceOrientation) -> Bool
{
return orientation.isValidInterfaceOrientation
}
#endif
//===----------------------------------------------------------------------===//
// UIInterfaceOrientation
//===----------------------------------------------------------------------===//
#if !os(watchOS) && !os(tvOS)
public extension UIInterfaceOrientation {
var isLandscape: Bool {
get { return self == .LandscapeLeft || self == .LandscapeRight }
}
var isPortrait: Bool {
get { return self == .Portrait || self == .PortraitUpsideDown }
}
}
@warn_unused_result
public func UIInterfaceOrientationIsPortrait(
orientation: UIInterfaceOrientation) -> Bool {
return orientation.isPortrait
}
@warn_unused_result
public func UIInterfaceOrientationIsLandscape(
orientation: UIInterfaceOrientation
) -> Bool {
return orientation.isLandscape
}
#endif
// Overlays for variadic initializers.
#if !os(watchOS) && !os(tvOS)
public extension UIActionSheet {
convenience init(title: String?,
delegate: UIActionSheetDelegate?,
cancelButtonTitle: String?,
destructiveButtonTitle: String?,
// Hack around overload ambiguity with non-variadic constructor.
// <rdar://problem/16704770>
otherButtonTitles firstButtonTitle: String,
_ moreButtonTitles: String...) {
self.init(title: title,
delegate: delegate,
cancelButtonTitle: cancelButtonTitle,
destructiveButtonTitle: destructiveButtonTitle)
self.addButtonWithTitle(firstButtonTitle)
for buttonTitle in moreButtonTitles {
self.addButtonWithTitle(buttonTitle)
}
}
}
#endif
#if !os(watchOS) && !os(tvOS)
public extension UIAlertView {
convenience init(title: String,
message: String,
delegate: UIAlertViewDelegate?,
cancelButtonTitle: String?,
// Hack around overload ambiguity with non-variadic constructor.
// <rdar://problem/16704770>
otherButtonTitles firstButtonTitle: String,
_ moreButtonTitles: String...) {
self.init(title: title,
message: message,
delegate: delegate,
cancelButtonTitle: cancelButtonTitle)
self.addButtonWithTitle(firstButtonTitle)
for buttonTitle in moreButtonTitles {
self.addButtonWithTitle(buttonTitle)
}
}
}
#endif
#if !os(watchOS)
struct _UIViewMirror : _MirrorType {
static var _views = NSMutableSet()
var _v : UIView
init(_ v : UIView) {_v = v}
var value: Any { get { return _v } }
var valueType: Any.Type { get { return (_v as Any).dynamicType } }
var objectIdentifier: ObjectIdentifier? { get { return .None } }
var count: Int { get { return 0 } }
subscript(_: Int) -> (String, _MirrorType) {
_preconditionFailure("_MirrorType access out of bounds")
}
var summary: String { get { return ""} }
var quickLookObject: PlaygroundQuickLook? {
// iOS 7 or greater only
var result: PlaygroundQuickLook? = nil
switch _UIViewMirror._views.member(_v) {
case nil:
_UIViewMirror._views.addObject(_v)
let bounds = _v.bounds
// in case of an empty rectangle abort the logging
if (bounds.size.width == 0) || (bounds.size.height == 0) {
return nil
}
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
// UIKit is about to update this to be optional, so make it work
// with both older and newer SDKs. (In this context it should always
// be present.)
let ctx: CGContext! = UIGraphicsGetCurrentContext()
UIColor(white:1.0, alpha:0.0).set()
CGContextFillRect(ctx, bounds)
_v.layer.renderInContext(ctx)
let image: UIImage! = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
result = .Some(.View(image))
_UIViewMirror._views.removeObject(_v)
default: ()
}
return result
}
var disposition : _MirrorDisposition { get { return .Aggregate } }
}
extension UIView : _Reflectable {
/// Returns a mirror that reflects `self`.
public func _getMirror() -> _MirrorType {
return _UIViewMirror(self)
}
}
#endif
#if SWIFT_ENABLE_OBJECT_LITERALS
extension UIColor : _ColorLiteralConvertible {
public required convenience init(colorLiteralRed red: Float, green: Float,
blue: Float, alpha: Float) {
self.init(red: CGFloat(red), green: CGFloat(green),
blue: CGFloat(blue), alpha: CGFloat(alpha))
}
}
public typealias _ColorLiteralType = UIColor
extension UIImage : _ImageLiteralConvertible {
private convenience init!(failableImageLiteral name: String) {
self.init(named: name)
}
public required convenience init(imageLiteral name: String) {
self.init(failableImageLiteral: name)
}
}
public typealias _ImageLiteralType = UIImage
#endif // SWIFT_ENABLE_OBJECT_LITERALS