Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from marty-suzuki/feature-0.2.0
Browse files Browse the repository at this point in the history
Feature 0.2.0
  • Loading branch information
marty-suzuki authored Feb 9, 2018
2 parents 864d18f + daa672b commit 616c8aa
Show file tree
Hide file tree
Showing 21 changed files with 1,016 additions and 272 deletions.
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: objective-c
matrix:
include:
- osx_image: xcode9.2
env:
global:
- LC_CTYPE=en_US.UTF-8
git:
submodules: false
branches:
only:
- master
script:
- xcodebuild test -workspace Continuum.xcworkspace -scheme ContinuumTests -configuration Debug -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 7" | xcpretty -c
notifications:
email:
on_success: never
on_failure: always
52 changes: 42 additions & 10 deletions Continuum.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,49 @@ import PlaygroundSupport

PlaygroundPage.current.needsIndefiniteExecution = true

class ViewModel {
var text = ""
// KeyPath
do {
class ViewModel {
var text = ""
}

let center = NotificationCenter()
let viewModel = ViewModel()
let label = UILabel()

_ = center.continuum.observe(viewModel, \.text, bindTo: label, \.text)
print("After observe: label.text = \(String(describing: label.text))")

viewModel.text = "Great Scott!"
center.continuum.post(keyPath: \ViewModel.text)
print("After post: label.text = \(String(describing: label.text))")
}

let center = NotificationCenter()
let viewModel = ViewModel()
let label = UILabel()
// Constant<Element> and Variable<Element>
do {
let center = NotificationCenter()

let variable = Variable(value: "")
let label = UILabel()

_ = center.continuum.observe(viewModel, \.text, bindTo: label, \.text)
print("After observe: label.text = \(String(describing: label.text))")
let constant = Constant(variable: variable)
let label2 = UILabel()

viewModel.text = "Great Scott!"
center.continuum.post(keyPath: \ViewModel.text)
print("After post: label.text = \(String(describing: label.text))")
_ = center.continuum.observe(variable, bindTo: label, \.text)
_ = center.continuum.observe(constant, bindTo: label2, \.text)
print("After observe: label.text = \(String(describing: label.text))")
print("After observe: label2.text = \(String(describing: label2.text))")

variable.value = "Nobody calls me chicken!"
print("After post: label.text = \(String(describing: label.text))")
print("After post: label2.text = \(String(describing: label2.text))")

let v2 = Variable<String?>(value: "")
_ = center.continuum.observe(constant, bindTo: v2, \Variable<String?>.value)
print("After observe: v2.value = \(v2.value)")

variable.value = "Back to the future!"
print("After post: label.text = \(String(describing: label.text))")
print("After post: label2.text = \(String(describing: label2.text))")
print("After post: v2.value = \(v2.value)")
}
2 changes: 1 addition & 1 deletion Continuum.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Continuum'
s.version = '0.1.0'
s.version = '0.2.0'
s.summary = 'NotificationCenter based Lightweight UI / AnyObject binder.'

# This description is used to generate tags and improve search results.
Expand Down
16 changes: 16 additions & 0 deletions Continuum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
379BCD2B202A00AE00450632 /* Wrappable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 379BCD2A202A00AE00450632 /* Wrappable.swift */; };
379BCD2D202A00F700450632 /* AnyKeyPath.extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 379BCD2C202A00F700450632 /* AnyKeyPath.extension.swift */; };
379BCD2F202A016600450632 /* Continuum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 379BCD2E202A016600450632 /* Continuum.swift */; };
9DF34AC2202C490A00809EF1 /* VariableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DF34AC1202C490A00809EF1 /* VariableTests.swift */; };
9DF34AC4202C493B00809EF1 /* ConstantTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DF34AC3202C493B00809EF1 /* ConstantTests.swift */; };
ED03FD7F202B52300084D73B /* Variable.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED03FD7E202B52300084D73B /* Variable.swift */; };
ED03FD81202B548A0084D73B /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED03FD80202B548A0084D73B /* Constant.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -37,6 +41,10 @@
379BCD2A202A00AE00450632 /* Wrappable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Wrappable.swift; sourceTree = "<group>"; };
379BCD2C202A00F700450632 /* AnyKeyPath.extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyKeyPath.extension.swift; sourceTree = "<group>"; };
379BCD2E202A016600450632 /* Continuum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Continuum.swift; sourceTree = "<group>"; };
9DF34AC1202C490A00809EF1 /* VariableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VariableTests.swift; sourceTree = "<group>"; };
9DF34AC3202C493B00809EF1 /* ConstantTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantTests.swift; sourceTree = "<group>"; };
ED03FD7E202B52300084D73B /* Variable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Variable.swift; sourceTree = "<group>"; };
ED03FD80202B548A0084D73B /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -84,6 +92,8 @@
379BCD132029FF9600450632 /* Info.plist */,
379BCD2A202A00AE00450632 /* Wrappable.swift */,
379BCD2E202A016600450632 /* Continuum.swift */,
ED03FD7E202B52300084D73B /* Variable.swift */,
ED03FD80202B548A0084D73B /* Constant.swift */,
);
path = Continuum;
sourceTree = "<group>";
Expand All @@ -93,6 +103,8 @@
children = (
379BCD1D2029FF9600450632 /* ContinuumTests.swift */,
379BCD1F2029FF9600450632 /* Info.plist */,
9DF34AC1202C490A00809EF1 /* VariableTests.swift */,
9DF34AC3202C493B00809EF1 /* ConstantTests.swift */,
);
path = ContinuumTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -221,6 +233,8 @@
379BCD2D202A00F700450632 /* AnyKeyPath.extension.swift in Sources */,
379BCD2F202A016600450632 /* Continuum.swift in Sources */,
379BCD2B202A00AE00450632 /* Wrappable.swift in Sources */,
ED03FD7F202B52300084D73B /* Variable.swift in Sources */,
ED03FD81202B548A0084D73B /* Constant.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -229,6 +243,8 @@
buildActionMask = 2147483647;
files = (
379BCD1E2029FF9600450632 /* ContinuumTests.swift in Sources */,
9DF34AC4202C493B00809EF1 /* ConstantTests.swift in Sources */,
9DF34AC2202C490A00809EF1 /* VariableTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
58 changes: 58 additions & 0 deletions Continuum.xcodeproj/xcshareddata/xcschemes/ContinuumTests.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "379BCD172029FF9600450632"
BuildableName = "ContinuumTests.xctest"
BlueprintName = "ContinuumTests"
ReferencedContainer = "container:Continuum.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
35 changes: 35 additions & 0 deletions Continuum/Constant.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Constant.swift
// Continuum
//
// Created by 鈴木大貴 on 2018/02/08.
// Copyright © 2018年 marty-suzuki. All rights reserved.
//

import Foundation

/// Constant is wrapper for value that has getter.
public final class Constant<Element>: ValueRepresentable, NotificationCenterSettable {
/// Gets current value of constant.
public var value: Element {
return _variable.value
}

/// Represents unique Notification.Name for each constants.
public var uniqueName: Notification.Name {
return _variable.uniqueName
}

private let _variable: Variable<E>

/// Initializes Constant with a Variable.
///
/// - parameter value: Variable.
public init(variable: Variable<E>) {
self._variable = variable
}

func setCenter(_ center: NotificationCenter) {
_variable.setCenter(center)
}
}
Loading

0 comments on commit 616c8aa

Please sign in to comment.