Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ playground.xcworkspace
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
.build/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

# CocoaPods
#
Expand Down
21 changes: 21 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// swift-tools-version:5.5
import PackageDescription

let package = Package(
name: "Stylish",
platforms: [
.macOS(.v10_15),
.iOS(.v9)
],
products: [
.library(name: "Stylish", targets: ["Stylish"])
],
targets: [
.target(
name: "Stylish",
path: "Stylish",
exclude: ["Info.plist", "Media.xcassets", "Stylish.h"]
)
],
swiftLanguageVersions: [.v5]
)
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,34 @@ For the first time, this provides a single solution for creating and applying st

## Installation

Since Swift has not yet reached ABI or module format stability, Apple does not support or advise distributing Swift libraries compiled outside of your project. Instead, the recommended approach is:
:warning: Because Stylish is a separate module from your app, some special considerations are needed to get IBDesignables and the live rendering of styles in Storyboards playing nicely. Specifically, it requires two extensions that override prepareForInterfaceBuilder in two types. See MainViewController.swift in the StylishExample app for reference implementations of these extensions.

### Manually
1. Include the Stylish repo (this repo) as a git submodule in your project (or just check out the version of the entire Stylish repo you want to use and add it to your project as a subdirectory)
2. Drag Stylish.xcodeproj into your own Xcode project or workspace (see the StylishExample project in this repo as a reference)
3. In your own app target(s) on the "General" tab, scroll down to "Embedded Binaries", click the plus button and choose Stylish.framework. Again, you can refer to the StylishExample project to see what this looks like.

These steps will ensure that the Stylish framework is compiled as part of your own app's build phases as needed and that the Stylish.framework will be using the same version of Swift and the Swift compiler as the rest of your project.

4. IMPORTANT! Because Stylish is a separate module from your app, some special considerations are needed to get IBDesignables and the live rendering of styles in Storyboards playing nicely. Specifically, it requires two extensions that override prepareForInterfaceBuilder in two types. See MainViewController.swift in the StylishExample app for reference implementations of these extensions.
### Carthage

[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate Alamofire into your Xcode project using Carthage, specify it in your `Cartfile`:

```ogdl
github "daniel-hall/Stylish" "master"
```

### Swift Package Manager

The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler.

Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.

```swift
dependencies: [
.package(url: "https://github.com/daniel-hall/Stylish.git", .branch("master"))
]
```

## Example Project

Expand Down
12 changes: 7 additions & 5 deletions Stylish.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
D7C472F41F3E4F8A00B5880A /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1320;
TargetAttributes = {
D7C472FC1F3E4F8A00B5880A = {
CreatedOnToolsVersion = 8.2.1;
Expand Down Expand Up @@ -189,6 +189,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -214,7 +215,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -252,6 +253,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -271,7 +273,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand All @@ -295,7 +297,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Stylish/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_NO_PIE = NO;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.danielhall.Stylish;
Expand All @@ -318,7 +320,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Stylish/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_NO_PIE = NO;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.danielhall.Stylish;
Expand Down
6 changes: 1 addition & 5 deletions Stylish.xcodeproj/xcshareddata/xcschemes/Stylish.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:Stylish.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
2 changes: 1 addition & 1 deletion Stylish/JSONStylesheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


import UIKit

/// A Stylish Stylesheet that can dynamically populate its member styles and style names by parsing them from a json file.
public class JSONStylesheet: Stylesheet {
Expand Down
2 changes: 1 addition & 1 deletion Stylish/PropertyStylers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ public struct UIViewStripedSubviewStyler: PropertyStyler {
/// MARK: - Convenience Protocols

/// A protocol to conform UILabel, UITextField and UITextView to, so they can be styled with the same Property Stylers
public protocol TextControl: class {
public protocol TextControl: AnyObject {
var textAlignment: NSTextAlignment { get set }
@available(iOS 10.0, *) var adjustsFontForContentSizeCategory: Bool { get set }
}
Expand Down
8 changes: 4 additions & 4 deletions Stylish/StylesheetParseableExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


import UIKit

// Add StylesheetParseable conformance to all the types used in the built-in PropertyStylers. This conformance converts the expected json value in the stylesheet (could be a String, a Bool, a Dictionary multiple key-values) into the corresponding Swift type

Expand Down Expand Up @@ -162,7 +162,7 @@ extension UITextAutocapitalizationType: StylesheetParseable {
public static func parse(from stylesheetValue: Any) -> UITextAutocapitalizationType? {
switch stylesheetValue as? String {
case .some("none"):
return .none
return UITextAutocapitalizationType.none
case .some("words"):
return .words
case .some("sentences"):
Expand Down Expand Up @@ -429,7 +429,7 @@ extension UIBaselineAdjustment: StylesheetParseable {
case .some("alignCenters"):
return .alignCenters
case .some("none"):
return .none
return UIBaselineAdjustment.none
default:
return nil
}
Expand All @@ -440,7 +440,7 @@ extension UITextField.BorderStyle: StylesheetParseable {
public static func parse(from stylesheetValue: Any) -> UITextField.BorderStyle? {
switch stylesheetValue as? String {
case .some("none"):
return .none
return UITextField.BorderStyle.none
case .some("line"):
return .line
case .some("bezel"):
Expand Down
4 changes: 2 additions & 2 deletions Stylish/Stylish.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import UIKit

/// A protocol that view types conform to in order to participate in the Stylish styling process. Requires a "styles" String property which can hold a comma-separated list of style names and "stylesheet" property which can hold an optional override stylesheet other than the global one, which will then be used by this Styleable instance and inherited by its children. Usually both required vars are implemented as IBInspectable properties
public protocol Styleable: class {
public protocol Styleable: AnyObject {
var styles: String { get set }
var stylesheet: String? { get set }
}
Expand All @@ -40,7 +40,7 @@ public protocol Style {
}

/// The protocol a type must conform to in order to be used as a Stylesheet. A Stylesheet is simply a dictionary of Styles, each associated with a name. A Stylesheet must also return the bundle it is associated with, in order for Styles / Property Stylers to know what bundle to retrieve images, colors, or other assets from
public protocol Stylesheet: class {
public protocol Stylesheet: AnyObject {
var styles: [String: Style] { get }
var bundle: Bundle { get }
}
Expand Down