Skip to content

Commit

Permalink
Merge pull request #46 from adly-holler/swift-1.2
Browse files Browse the repository at this point in the history
Swift 1.2 compatibility
  • Loading branch information
joshaber committed Apr 12, 2015
2 parents 99253b5 + 5021cd4 commit 8bb4190
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 39 deletions.
2 changes: 1 addition & 1 deletion External/Quick
Submodule Quick updated 59 files
+0 −5 .travis.yml
+4 −0 CONTRIBUTING.md
+220 −0 Documentation/ArrangeActAssert.md
+87 −0 Documentation/BehavioralTesting.md
+103 −0 Documentation/ConfiguringQuick.md
+28 −0 Documentation/InstallingFileTemplates.md
+141 −0 Documentation/InstallingQuick.md
+28 −0 Documentation/MoreResources.md
+106 −0 Documentation/NimbleAssertions.md
+462 −0 Documentation/QuickExamplesAndGroups.md
+53 −0 Documentation/QuickInObjectiveC.md
+42 −0 Documentation/README.md
+73 −0 Documentation/SettingUpYourXcodeProject.md
+125 −0 Documentation/SharedExamples.md
+179 −0 Documentation/TestingApps.md
+1 −1 Externals/Nimble
+4 −3 Quick.podspec
+325 −62 Quick.xcodeproj/project.pbxproj
+28 −0 Quick.xcodeproj/xcshareddata/xcschemes/Quick-OSX.xcscheme
+10 −0 Quick.xcodeproj/xcshareddata/xcschemes/Quick-iOS.xcscheme
+9 −1 Quick/Callsite.swift
+54 −1 Quick/Configuration/Configuration.swift
+53 −19 Quick/DSL/DSL.swift
+31 −11 Quick/DSL/QCKDSL.h
+21 −9 Quick/DSL/QCKDSL.m
+37 −11 Quick/DSL/World+DSL.swift
+26 −2 Quick/Example.swift
+16 −4 Quick/ExampleGroup.swift
+1 −1 Quick/ExampleMetadata.swift
+1 −1 Quick/Failure.swift
+29 −0 Quick/Filter.swift
+1 −1 Quick/Hooks/ExampleHooks.swift
+1 −1 Quick/Hooks/SuiteHooks.swift
+1 −2 Quick/QuickSpec.m
+50 −10 Quick/World.swift
+56 −0 QuickFocusedTests/FocusedTests+ObjC.m
+48 −0 QuickFocusedTests/FocusedTests.swift
+24 −0 QuickFocusedTests/Info.plist
+0 −25 QuickTests/ExampleMetadataFunctionalTests.swift
+1 −1 QuickTests/Fixtures/FunctionalTests_SharedExamplesTests_SharedExamples.swift
+0 −27 QuickTests/Fixtures/Person.swift
+0 −11 QuickTests/Fixtures/Poet.swift
+0 −65 QuickTests/FunctionalTests+ObjC.m
+0 −156 QuickTests/FunctionalTests.swift
+81 −0 QuickTests/FunctionalTests/AfterEachTests+ObjC.m
+52 −28 QuickTests/FunctionalTests/AfterEachTests.swift
+42 −0 QuickTests/FunctionalTests/AfterSuiteTests+ObjC.m
+1 −1 QuickTests/FunctionalTests/AfterSuiteTests.swift
+68 −0 QuickTests/FunctionalTests/BeforeEachTests+ObjC.m
+35 −27 QuickTests/FunctionalTests/BeforeEachTests.swift
+39 −0 QuickTests/FunctionalTests/BeforeSuiteTests+ObjC.m
+1 −1 QuickTests/FunctionalTests/BeforeSuiteTests.swift
+36 −0 QuickTests/FunctionalTests/ItTests+ObjC.m
+60 −0 QuickTests/FunctionalTests/PendingTests+ObjC.m
+1 −1 QuickTests/FunctionalTests/PendingTests.swift
+59 −0 QuickTests/FunctionalTests/SharedExamples+BeforeEachTests+ObjC.m
+36 −0 QuickTests/FunctionalTests/SharedExamplesTests+ObjC.m
+0 −21 QuickTests/FunctionalTests/WorldExampleMetadataFunctionalTests.swift
+9 −944 README.md
2 changes: 1 addition & 1 deletion Few-Mac/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Button: Element {
button.enabled = enabled
}

let oldButton = old as Button
let oldButton = old as! Button
if isDefault != oldButton.isDefault {
if isDefault {
button.keyEquivalent = "\r"
Expand Down
2 changes: 1 addition & 1 deletion Few-Mac/Input.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class InputDelegate: NSObject, NSTextFieldDelegate {
var action: (NSTextField -> ())?

override func controlTextDidChange(notification: NSNotification) {
let field = notification.object as NSTextField
let field = notification.object as! NSTextField
action?(field)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Few-Mac/QuickLook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ extension Element {
}

public var ql: ViewType {
return debugQuickLookObject()! as ViewType
return debugQuickLookObject()! as! ViewType
}
}
10 changes: 5 additions & 5 deletions Few-Mac/ScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ private class ScrollViewElement: Element {
}

private override func addRealizedChildView(childView: ViewType, selfView: ViewType) {
let scrollVew = selfView as FewScrollView
let scrollVew = selfView as! FewScrollView
scrollVew.scrollView.documentView = childView
}

private override func realize() -> RealizedElement {
let realizedElement = super.realize()

let scrollView = realizedElement.view as FewScrollView
let documentView = scrollView.scrollView.documentView as NSView
let scrollView = realizedElement.view as! FewScrollView
let documentView = scrollView.scrollView.documentView as! NSView

let top = CGPointMake(0, documentView.bounds.size.height);
documentView.scrollPoint(top)
Expand All @@ -84,7 +84,7 @@ private class ScrollViewElement: Element {
private override func applyDiff(old: Element, realizedSelf: RealizedElement?) {
super.applyDiff(old, realizedSelf: realizedSelf)

let scrollView = realizedSelf?.view as FewScrollView
let scrollView = realizedSelf?.view as! FewScrollView
scrollView.didScroll = didScroll
}
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public class ScrollView_<LOL>: Component<CGRect> {
}

private class func render(c: Component<CGRect>, visibleRect: CGRect) -> Element {
let component = c as ScrollView_
let component = c as! ScrollView_

let visibleElements = component.calculateVisibleElements(visibleRect)

Expand Down
2 changes: 1 addition & 1 deletion Few-Mac/TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private class TableViewHandler: NSObject, NSTableViewDelegate, NSTableViewDataSo
let element = elements[row]

let key = "ListCell"
var listCell = tableView.makeViewWithIdentifier(key, owner: nil) as FewListCell?
var listCell = tableView.makeViewWithIdentifier(key, owner: nil) as! FewListCell?
if listCell == nil {
let newListCell = FewListCell(frame: CGRectZero)
newListCell.identifier = key
Expand Down
8 changes: 4 additions & 4 deletions Few-iOS/ScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ private class ScrollViewElement: Element {
}

private override func addRealizedChildView(childView: ViewType, selfView: ViewType) {
let scrollView = selfView as FewScrollView
let scrollView = selfView as! FewScrollView
scrollView.subviews.first?.removeFromSuperview()
scrollView.addSubview(childView)
}

private override func realize() -> RealizedElement {
let realizedElement = super.realize()

let scrollView = realizedElement.view as FewScrollView
let scrollView = realizedElement.view as! FewScrollView
if let element = children.first {
scrollView.contentSize = element.frame.size
}
Expand All @@ -62,7 +62,7 @@ private class ScrollViewElement: Element {
private override func applyDiff(old: Element, realizedSelf: RealizedElement?) {
super.applyDiff(old, realizedSelf: realizedSelf)

let scrollView = realizedSelf?.view as FewScrollView
let scrollView = realizedSelf?.view as! FewScrollView
scrollView.didScroll = didScroll
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public class ScrollView_<LOL>: Component<CGRect> {
}

private class func render(c: Component<CGRect>, visibleRect: CGRect) -> Element {
let component = c as ScrollView_
let component = c as! ScrollView_

let visibleElements = component.calculateVisibleElements(visibleRect)

Expand Down
12 changes: 6 additions & 6 deletions Few-iOS/TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private class TableViewHandler: NSObject, UITableViewDelegate, UITableViewDataSo

// MARK: NSTableViewDelegate

private func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
@objc func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let element = elements[indexPath.row]

let key = "ListCell"
Expand All @@ -71,20 +71,20 @@ private class TableViewHandler: NSObject, UITableViewDelegate, UITableViewDataSo
return listCell ?? UITableViewCell()
}

private func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
@objc func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let height = elements[indexPath.row].frame.height
return height > CGFloat(0) ? height : defaultRowHeight
}

private func numberOfSectionsInTableView(tableView: UITableView) -> Int {
@objc func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

private func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
@objc func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return elements.count
}
private func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
@objc func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectionChanged?(indexPath.row)
}
}
Expand Down
6 changes: 2 additions & 4 deletions Few.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,6 @@
);
INFOPLIST_FILE = "Few-iOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = Few;
SDKROOT = iphoneos;
Expand All @@ -911,7 +910,6 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Few-iOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = Few;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -955,6 +953,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -993,6 +992,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -1111,7 +1111,6 @@
"$(inherited)",
);
INFOPLIST_FILE = "FewDemo-iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand All @@ -1128,7 +1127,6 @@
COPY_PHASE_STRIP = NO;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = "FewDemo-iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand Down
4 changes: 2 additions & 2 deletions FewCore/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public func id<T>(val: T) -> T {
return val
}

public func void<T>(fn: @autoclosure () -> T) {
public func void<T>(@autoclosure fn: () -> T) {
fn()
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public func flip<A, B, C>(fn: (A, B) -> C) -> (B, A) -> C {
}
}

public func maybe<A, B>(value: A?, none: @autoclosure () -> B, some: A -> B) -> B {
public func maybe<A, B>(value: A?, @autoclosure none: () -> B, some: A -> B) -> B {
if let value = value {
return some(value)
} else {
Expand Down
2 changes: 1 addition & 1 deletion FewDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
private let appComponent = Component(initialState: .Converter, render: renderApp)

func applicationDidFinishLaunching(notification: NSNotification) {
let contentView = window.contentView as NSView
let contentView = window.contentView as! NSView
appComponent.addToView(contentView)
}
}
18 changes: 13 additions & 5 deletions FewDemo/Demo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import Few
import AppKit

struct LoginState {
let username: String = ""
let password: String = ""
let username: String
let password: String
init(username: String = "", password: String = "") {
self.username = username
self.password = password
}
}

private func renderInput(component: Few.Component<LoginState>, label: String, secure: Bool, fn: (LoginState, String) -> LoginState) -> Element {
Expand All @@ -37,8 +41,12 @@ private func renderInput(component: Few.Component<LoginState>, label: String, se
}

struct ScrollViewState {
let selectedRow: Int? = nil
let items: [Int] = Array(1...100)
let selectedRow: Int?
let items: [Int]
init(items: [Int] = Array(1...100), selectedRow: Int? = nil) {
self.items = items
self.selectedRow = selectedRow
}
}

private func keyDown(event: NSEvent, component: Few.Component<ScrollViewState>) -> Bool {
Expand Down Expand Up @@ -91,7 +99,7 @@ private func renderLogin() -> Element {
return Element()
.direction(.Column)
.children([
renderThingy(state.username.utf16Count),
renderThingy(count(state.username.utf16)),
renderInput(component, "Username", false) {
LoginState(username: $1, password: $0.password)
},
Expand Down
8 changes: 6 additions & 2 deletions FewDemo/TemperatureConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import Few
struct ConverterState {
static let defaultFahrenheit: CGFloat = 32

let fahrenheit = defaultFahrenheit
let celcius = f2c(defaultFahrenheit)
let fahrenheit: CGFloat
let celcius: CGFloat
init(fahrenheit: CGFloat = defaultFahrenheit, celcius: CGFloat = f2c(defaultFahrenheit)) {
self.fahrenheit = fahrenheit
self.celcius = celcius
}
}

private func c2f(c: CGFloat) -> CGFloat {
Expand Down
2 changes: 1 addition & 1 deletion FewDemo/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

import Cocoa

NSApplicationMain(C_ARGC, C_ARGV)
NSApplicationMain(Process.argc, Process.unsafeArgv)
6 changes: 3 additions & 3 deletions FewTests/DiffTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DiffTests: QuickSpec {
let view = button.realize()
let realizedButton = RealizedElement(element: button, children: [], view: view)

let label = Label(text: "Hey")
let label = Label("Hey")

it("should detect simple diffing") {
let diff = diffElementLists([realizedButton], [button])
Expand Down Expand Up @@ -51,8 +51,8 @@ class DiffTests: QuickSpec {
let labelView = label.realize()
let realizedLabel = RealizedElement(element: label, children: [], view: labelView)

let newLabel = Label(text: "No.").key("key")

let newLabel = Label("No.")
newLabel.key = "key"
let diff = diffElementLists([realizedButton, realizedLabel], [button, newLabel, label])
expect(diff.add.count).to(equal(1))
expect(diff.remove.count).to(equal(0))
Expand Down

0 comments on commit 8bb4190

Please sign in to comment.