Files
swift-mirror/stdlib/objc/UIKit/UIKit.swift
Jordan Rose cca27d02a0 Tag everything in the standard library with accessibility attributes.
Keep calm: remember that the standard library has many more public exports
than the average target, and that this contains ALL of them at once.
I also deliberately tried to tag nearly every top-level decl, even if that
was just to explicitly mark things @internal, to make sure I didn't miss
something.

This does export more than we might want to, mostly for protocol conformance
reasons, along with our simple-but-limiting typealias rule. I tried to also
mark things private where possible, but it's really going to be up to the
standard library owners to get this right. This is also only validated
against top-level access control; I haven't fully tested against member-level
access control yet, and none of our semantic restrictions are in place.

Along the way I also noticed bits of stdlib cruft; to keep this patch
understandable, I didn't change any of them.

Swift SVN r19145
2014-06-24 21:32:18 +00:00

192 lines
5.2 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
// Overlay UIApplicationMain, which is declared with a non-const char *argv[]
// argument that gets mapped to UnsafePointer<UnsafePointer<CChar>> by the
// importer, with one that takes UnsafePointer<CString> instead, matching the
// type of C_ARGV.
@asmname("UIApplicationMain") @public
func UIApplicationMain(argc: CInt,
argv: UnsafePointer<CString>,
principalClassName: NSString?,
delegateClassName: NSString?) -> CInt
// These are un-imported macros in UIKit.
@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
}
}
}
}
@public
func UIDeviceOrientationIsLandscape(orientation: UIDeviceOrientation) -> Bool {
return orientation.isLandscape
}
@public
func UIDeviceOrientationIsPortrait(orientation: UIDeviceOrientation) -> Bool {
return orientation.isPortrait
}
@public
func UIDeviceOrientationIsValidInterfaceOrientation(
orientation: UIDeviceOrientation) -> Bool
{
return orientation.isValidInterfaceOrientation
}
@public extension UIInterfaceOrientation {
var isLandscape: Bool {
get { return self == .LandscapeLeft || self == .LandscapeRight }
}
var isPortrait: Bool {
get { return self == .Portrait || self == .PortraitUpsideDown }
}
}
@public
func UIInterfaceOrientationIsPortrait(orientation: UIInterfaceOrientation)
-> Bool
{
return orientation.isPortrait
}
@public
func UIInterfaceOrientationIsLandscape(orientation: UIInterfaceOrientation)
-> Bool
{
return orientation.isLandscape
}
// Overlays for variadic initializers.
@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)
}
}
}
@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)
}
}
}
struct _UIViewMirror : Mirror {
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,Mirror) { get { _fatalError("Mirror access out of bounds") } }
var summary: String { get { return ""} }
var quickLookObject: QuickLookObject? {
// iOS 7 or greater only
let bounds = _v.bounds
// in case of an empty rectangle abort the logging
if (bounds.size.width == 0) || (bounds.size.height == 0) {
return nil
}
UIGraphicsBeginImageContext(bounds.size)
var ctx = UIGraphicsGetCurrentContext()
UIColor(white:1.0, alpha:0.0).set()
CGContextFillRect(ctx, bounds)
_v.layer.renderInContext(ctx)
var maybe_image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
if let image = maybe_image {
return .Some(.View(image))
}
return nil
}
var disposition : MirrorDisposition { get { return .Aggregate } }
}
extension UIView : Reflectable {
@public func getMirror() -> Mirror {
return _UIViewMirror(self)
}
}