Skip to content

Commit

Permalink
Adding files
Browse files Browse the repository at this point in the history
  • Loading branch information
bradhilton committed Feb 9, 2016
1 parent 466a77e commit 53d8b60
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 9 deletions.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2014 Skyvive <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
18 changes: 18 additions & 0 deletions PropertyExtensions.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Pod::Spec.new do |s|
s.name = "PropertyExtensions"
s.version = "1.0.3"
s.summary = "Add Stored Properties In Swift Class Extensions"
s.description = <<-DESC
PropertyExtensions allows you to dynamically add properties to your class extensions.
DESC
s.homepage = "https://github.com/bradhilton/PropertyExtensions"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Brad Hilton" => "[email protected]" }
s.source = { :git => "https://github.com/bradhilton/PropertyExtensions.git", :tag => "1.0.3" }

s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.9"

s.source_files = "PropertyExtensions", "PropertyExtensions/**/*.{swift,h,m}"
s.requires_arc = true
end
11 changes: 11 additions & 0 deletions PropertyExtensions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

/* Begin PBXBuildFile section */
A23A21F31C6A4CB7005E4020 /* PropertyExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = A23A21F21C6A4CB7005E4020 /* PropertyExtensions.h */; settings = {ATTRIBUTES = (Public, ); }; };
A23A21FD1C6A4D8D005E4020 /* PropertyExtensions.podspec in Resources */ = {isa = PBXBuildFile; fileRef = A23A21FC1C6A4D8D005E4020 /* PropertyExtensions.podspec */; };
A23A21FF1C6A4DE1005E4020 /* PropertyExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A23A21FE1C6A4DE1005E4020 /* PropertyExtensions.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
A23A21EF1C6A4CB7005E4020 /* PropertyExtensions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PropertyExtensions.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A23A21F21C6A4CB7005E4020 /* PropertyExtensions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PropertyExtensions.h; sourceTree = "<group>"; };
A23A21F41C6A4CB7005E4020 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A23A21FC1C6A4D8D005E4020 /* PropertyExtensions.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PropertyExtensions.podspec; sourceTree = "<group>"; };
A23A21FE1C6A4DE1005E4020 /* PropertyExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PropertyExtensions.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -32,6 +36,7 @@
children = (
A23A21F11C6A4CB7005E4020 /* PropertyExtensions */,
A23A21F01C6A4CB7005E4020 /* Products */,
A23A21FC1C6A4D8D005E4020 /* PropertyExtensions.podspec */,
);
sourceTree = "<group>";
};
Expand All @@ -48,6 +53,7 @@
children = (
A23A21F21C6A4CB7005E4020 /* PropertyExtensions.h */,
A23A21F41C6A4CB7005E4020 /* Info.plist */,
A23A21FE1C6A4DE1005E4020 /* PropertyExtensions.swift */,
);
path = PropertyExtensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -120,6 +126,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A23A21FD1C6A4D8D005E4020 /* PropertyExtensions.podspec in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -130,6 +137,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A23A21FF1C6A4DE1005E4020 /* PropertyExtensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -228,6 +236,7 @@
A23A21F81C6A4CB7005E4020 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -238,12 +247,14 @@
PRODUCT_BUNDLE_IDENTIFIER = com.bradhilton.PropertyExtensions;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
A23A21F91C6A4CB7005E4020 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A23A21EE1C6A4CB7005E4020"
BuildableName = "PropertyExtensions.framework"
BlueprintName = "PropertyExtensions"
ReferencedContainer = "container:PropertyExtensions.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
Expand All @@ -26,6 +42,15 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A23A21EE1C6A4CB7005E4020"
BuildableName = "PropertyExtensions.framework"
BlueprintName = "PropertyExtensions"
ReferencedContainer = "container:PropertyExtensions.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand All @@ -35,6 +60,15 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A23A21EE1C6A4CB7005E4020"
BuildableName = "PropertyExtensions.framework"
BlueprintName = "PropertyExtensions"
ReferencedContainer = "container:PropertyExtensions.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
9 changes: 0 additions & 9 deletions PropertyExtensions/PropertyExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,5 @@
// Copyright © 2016 Brad Hilton. All rights reserved.
//

#import <UIKit/UIKit.h>

//! Project version number for PropertyExtensions.
FOUNDATION_EXPORT double PropertyExtensionsVersionNumber;

//! Project version string for PropertyExtensions.
FOUNDATION_EXPORT const unsigned char PropertyExtensionsVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <PropertyExtensions/PublicHeader.h>


51 changes: 51 additions & 0 deletions PropertyExtensions/PropertyExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// PropertyExtensions.swift
// PropertyExtensions
//
// Created by Bradley Hilton on 2/9/16.
// Copyright © 2016 Brad Hilton. All rights reserved.
//

import ObjectiveC.runtime

protocol PropertyExtensions : class {}

extension PropertyExtensions {

func getProperty<T>(property: String) -> T? {
return (objc_getAssociatedObject(self, property.associatedValueKey) as? AssociatedValue)?.value as? T
}

func getProperty<T>(property: String, initial: T) -> T {
if let value: T = getProperty(property) {
return value
} else {
setValue(initial, forProperty: property)
return initial
}
}

func setValue<T>(value: T?, forProperty property: String) {
objc_setAssociatedObject(self, property.associatedValueKey, AssociatedValue(value: value), .OBJC_ASSOCIATION_RETAIN)
}

}

extension String {

private var associatedValueKey: UnsafePointer<Void> {
return UnsafePointer<Void>(bitPattern: abs(hashValue))
}

}

private class AssociatedValue {

var value: Any? = nil

init?(value: Any?) {
guard value != nil else { return nil }
self.value = value
}

}
Loading

0 comments on commit 53d8b60

Please sign in to comment.