Selaa lähdekoodia

Move files into Lib dir

Evgenii Neumerzhitckii 10 vuotta sitten
vanhempi
commit
fa961d9b24

+ 303 - 0
Distrib/TegKeychainDistrib.swift

@@ -0,0 +1,303 @@
+//
+// Keychain helper for iOS/Swift.
+//
+// https://github.com/exchangegroup/keychain-swift
+//
+// This file was automatically generated by combining multiple Swift source files.
+//
+
+
+// ----------------------------
+//
+// TegKeychain.swift
+//
+// ----------------------------
+
+import UIKit
+import Security
+
+
+/**
+
+A collection of helper functions for saving text and data in the keychain.
+
+*/
+public class TegKeychain {
+  
+  static var lastQueryParameters: [String: NSObject]? // Used by unit tests
+  
+  /**
+  
+  Stores the text value in the keychain item under the given key.
+  
+  :param: key Key under which the text value is stored in the keychain.
+  :param: value Text string to be written to the keychain.
+  :param: withAccess Value that indicates when your app needs access to the text in the keychain item. By default the .AccessibleWhenUnlocked option is used that permits the data to be accessed only while the device is unlocked by the user.
+
+  */
+  public class func set(value: String, forKey key: String,
+    withAccess access: TegKeychainAccessOptions? = nil) -> Bool {
+    
+    if let value = value.dataUsingEncoding(NSUTF8StringEncoding) {
+      return set(value, forKey: key, withAccess: access)
+    }
+    
+    return false
+  }
+
+  /**
+  
+  Stores the data in the keychain item under the given key.
+  
+  :param: key Key under which the data is stored in the keychain.
+  :param: value Data to be written to the keychain.
+  :param: withAccess Value that indicates when your app needs access to the text in the keychain item. By default the .AccessibleWhenUnlocked option is used that permits the data to be accessed only while the device is unlocked by the user.
+  
+  :returns: True if the text was successfully written to the keychain.
+  
+  */
+  public class func set(value: NSData, forKey key: String,
+    withAccess access: TegKeychainAccessOptions? = nil) -> Bool {
+
+    let accessible = access?.value ?? TegKeychainAccessOptions.defaultOption.value
+      
+    let query = [
+      TegKeychainConstants.klass       : TegKeychainConstants.classGenericPassword,
+      TegKeychainConstants.attrAccount : key,
+      TegKeychainConstants.valueData   : value,
+      TegKeychainConstants.accessible  : accessible
+    ]
+      
+    lastQueryParameters = query
+          
+    SecItemDelete(query as CFDictionaryRef)
+    
+    let status: OSStatus = SecItemAdd(query as CFDictionaryRef, nil)
+    
+    return status == noErr
+  }
+
+  /**
+  
+  Retrieves the text value from the keychain that corresponds to the given key.
+  
+  :param: key The key that is used to read the keychain item.
+  :returns: The text value from the keychain. Returns nil if unable to read the item.
+  
+  */
+  public class func get(key: String) -> String? {
+    if let data = getData(key),
+      let currentString = NSString(data: data, encoding: NSUTF8StringEncoding) as? String {
+
+      return currentString
+    }
+
+    return nil
+  }
+
+  /**
+  
+  Retrieves the data from the keychain that corresponds to the given key.
+  
+  :param: key The key that is used to read the keychain item.
+  :returns: The text value from the keychain. Returns nil if unable to read the item.
+  
+  */
+  public class func getData(key: String) -> NSData? {
+    let query = [
+      TegKeychainConstants.klass       : kSecClassGenericPassword,
+      TegKeychainConstants.attrAccount : key,
+      TegKeychainConstants.returnData  : kCFBooleanTrue,
+      TegKeychainConstants.matchLimit  : kSecMatchLimitOne ]
+    
+    var result: AnyObject?
+    
+    let status = withUnsafeMutablePointer(&result) {
+      SecItemCopyMatching(query, UnsafeMutablePointer($0))
+    }
+    
+    if status == noErr { return result as? NSData }
+    
+    return nil
+  }
+
+  /**
+  
+  Deletes the single keychain item specified by the key.
+  
+  :param: key The key that is used to delete the keychain item.
+  :returns: True if the item was successfully deleted.
+  
+  */
+  public class func delete(key: String) -> Bool {
+    let query = [
+      TegKeychainConstants.klass       : kSecClassGenericPassword,
+      TegKeychainConstants.attrAccount : key ]
+    
+    let status: OSStatus = SecItemDelete(query as CFDictionaryRef)
+    
+    return status == noErr
+  }
+
+  /**
+  
+  Deletes all keychain items used by the app.
+  
+  :returns: True if the keychain items were successfully deleted.
+  
+  */
+  public class func clear() -> Bool {
+    let query = [ kSecClass as String : kSecClassGenericPassword ]
+    
+    let status: OSStatus = SecItemDelete(query as CFDictionaryRef)
+    
+    return status == noErr
+  }
+}
+
+
+// ----------------------------
+//
+// TegKeychainAccessOptions.swift
+//
+// ----------------------------
+
+import Security
+
+/**
+
+These options are used to determine when a keychain item should be readable. The default value is AccessibleWhenUnlocked.
+
+*/
+public enum TegKeychainAccessOptions {
+  
+  /**
+  
+  The data in the keychain item can be accessed only while the device is unlocked by the user.
+  
+  This is recommended for items that need to be accessible only while the application is in the foreground. Items with this attribute migrate to a new device when using encrypted backups.
+  
+  This is the default value for keychain items added without explicitly setting an accessibility constant.
+  
+  */
+  case AccessibleWhenUnlocked
+  
+  /**
+  
+  The data in the keychain item can be accessed only while the device is unlocked by the user.
+  
+  This is recommended for items that need to be accessible only while the application is in the foreground. Items with this attribute do not migrate to a new device. Thus, after restoring from a backup of a different device, these items will not be present.
+  
+  */
+  case AccessibleWhenUnlockedThisDeviceOnly
+  
+  /**
+  
+  The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user.
+  
+  After the first unlock, the data remains accessible until the next restart. This is recommended for items that need to be accessed by background applications. Items with this attribute migrate to a new device when using encrypted backups.
+  
+  */
+  case AccessibleAfterFirstUnlock
+  
+  /**
+  
+  The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user.
+  
+  After the first unlock, the data remains accessible until the next restart. This is recommended for items that need to be accessed by background applications. Items with this attribute do not migrate to a new device. Thus, after restoring from a backup of a different device, these items will not be present.
+  
+  */
+  case AccessibleAfterFirstUnlockThisDeviceOnly
+  
+  /**
+  
+  The data in the keychain item can always be accessed regardless of whether the device is locked.
+  
+  This is not recommended for application use. Items with this attribute migrate to a new device when using encrypted backups.
+  
+  */
+  case AccessibleAlways
+  
+  /**
+  
+  The data in the keychain can only be accessed when the device is unlocked. Only available if a passcode is set on the device.
+  
+  This is recommended for items that only need to be accessible while the application is in the foreground. Items with this attribute never migrate to a new device. After a backup is restored to a new device, these items are missing. No items can be stored in this class on devices without a passcode. Disabling the device passcode causes all items in this class to be deleted.
+  
+  */
+  case AccessibleWhenPasscodeSetThisDeviceOnly
+  
+  /**
+  
+  The data in the keychain item can always be accessed regardless of whether the device is locked.
+  
+  This is not recommended for application use. Items with this attribute do not migrate to a new device. Thus, after restoring from a backup of a different device, these items will not be present.
+  
+  */
+  case AccessibleAlwaysThisDeviceOnly
+  
+  static var defaultOption: TegKeychainAccessOptions {
+    return .AccessibleWhenUnlocked
+  }
+  
+  var value: String {
+    switch self {
+    case .AccessibleWhenUnlocked:
+      return toString(kSecAttrAccessibleWhenUnlocked)
+      
+    case .AccessibleWhenUnlockedThisDeviceOnly:
+      return toString(kSecAttrAccessibleWhenUnlockedThisDeviceOnly)
+      
+    case .AccessibleAfterFirstUnlock:
+      return toString(kSecAttrAccessibleAfterFirstUnlock)
+      
+    case .AccessibleAfterFirstUnlockThisDeviceOnly:
+      return toString(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly)
+      
+    case .AccessibleAlways:
+      return toString(kSecAttrAccessibleAlways)
+      
+    case .AccessibleWhenPasscodeSetThisDeviceOnly:
+      return toString(kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly)
+      
+    case .AccessibleAlwaysThisDeviceOnly:
+      return toString(kSecAttrAccessibleAlwaysThisDeviceOnly)
+    }
+  }
+  
+  func toString(value: CFStringRef) -> String {
+    return TegKeychainConstants.toString(value)
+  }
+}
+
+
+// ----------------------------
+//
+// TegKeychainConstants.swift
+//
+// ----------------------------
+
+import Foundation
+import Security
+
+public struct TegKeychainConstants {
+  public static var klass: String { return toString(kSecClass) }
+  public static var classGenericPassword: String { return toString(kSecClassGenericPassword) }
+  public static var attrAccount: String { return toString(kSecAttrAccount) }
+  public static var valueData: String { return toString(kSecValueData) }
+  public static var returnData: String { return toString(kSecReturnData) }
+  public static var matchLimit: String { return toString(kSecMatchLimit) }
+
+  /**
+  
+  A value that indicates when your app needs access to the data in a keychain item. The default value is AccessibleWhenUnlocked. For a list of possible values, see TegKeychainAccessOptions.
+  
+  */
+  public static var accessible: String { return toString(kSecAttrAccessible) }
+
+  static func toString(value: CFStringRef) -> String {
+    return (value as? String) ?? ""
+  }
+}
+
+

+ 61 - 21
keychain.xcodeproj/project.pbxproj

@@ -7,7 +7,6 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		2B48E33A1A92F47800456D2F /* TegKeychainConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B48E3391A92F47800456D2F /* TegKeychainConstants.swift */; };
 		2BCB00921A83354D0022C93A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BCB00911A83354D0022C93A /* AppDelegate.swift */; };
 		2BCB00941A83354D0022C93A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BCB00931A83354D0022C93A /* ViewController.swift */; };
 		2BCB00971A83354D0022C93A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2BCB00951A83354D0022C93A /* Main.storyboard */; };
@@ -15,11 +14,13 @@
 		2BCB009C1A83354D0022C93A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2BCB009A1A83354D0022C93A /* LaunchScreen.xib */; };
 		2BCB00A81A83354D0022C93A /* keychainTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BCB00A71A83354D0022C93A /* keychainTests.swift */; };
 		2BCB00B21A8335740022C93A /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2BCB00B11A8335740022C93A /* Default-568h@2x.png */; };
-		2BCB00B51A8335AF0022C93A /* TegKeychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BCB00B41A8335AF0022C93A /* TegKeychain.swift */; };
-		7E49F5361B1BE41B00FBC3FF /* TegKeychainAccessOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E49F5351B1BE41B00FBC3FF /* TegKeychainAccessOptions.swift */; };
-		7E49F5371B1BEE0B00FBC3FF /* TegKeychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BCB00B41A8335AF0022C93A /* TegKeychain.swift */; };
-		7E49F5381B1BEE0D00FBC3FF /* TegKeychainAccessOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E49F5351B1BE41B00FBC3FF /* TegKeychainAccessOptions.swift */; };
-		7E49F5391B1BEE0F00FBC3FF /* TegKeychainConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B48E3391A92F47800456D2F /* TegKeychainConstants.swift */; };
+		7E49F53C1B1BF14500FBC3FF /* concatenate_swift_files.sh in Resources */ = {isa = PBXBuildFile; fileRef = 7E49F53B1B1BF14500FBC3FF /* concatenate_swift_files.sh */; };
+		7E49F5421B1BF1FE00FBC3FF /* TegKeychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E49F53F1B1BF1FE00FBC3FF /* TegKeychain.swift */; };
+		7E49F5431B1BF1FE00FBC3FF /* TegKeychainAccessOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E49F5401B1BF1FE00FBC3FF /* TegKeychainAccessOptions.swift */; };
+		7E49F5441B1BF1FE00FBC3FF /* TegKeychainConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E49F5411B1BF1FE00FBC3FF /* TegKeychainConstants.swift */; };
+		7E49F5451B1BF20A00FBC3FF /* TegKeychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E49F53F1B1BF1FE00FBC3FF /* TegKeychain.swift */; };
+		7E49F5461B1BF20C00FBC3FF /* TegKeychainAccessOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E49F5401B1BF1FE00FBC3FF /* TegKeychainAccessOptions.swift */; };
+		7E49F5471B1BF20E00FBC3FF /* TegKeychainConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E49F5411B1BF1FE00FBC3FF /* TegKeychainConstants.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -33,7 +34,6 @@
 /* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
-		2B48E3391A92F47800456D2F /* TegKeychainConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TegKeychainConstants.swift; sourceTree = "<group>"; };
 		2BCB008C1A83354D0022C93A /* keychain.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = keychain.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		2BCB00901A83354D0022C93A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		2BCB00911A83354D0022C93A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -45,8 +45,11 @@
 		2BCB00A61A83354D0022C93A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		2BCB00A71A83354D0022C93A /* keychainTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = keychainTests.swift; sourceTree = "<group>"; };
 		2BCB00B11A8335740022C93A /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
-		2BCB00B41A8335AF0022C93A /* TegKeychain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TegKeychain.swift; sourceTree = "<group>"; };
-		7E49F5351B1BE41B00FBC3FF /* TegKeychainAccessOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TegKeychainAccessOptions.swift; sourceTree = "<group>"; };
+		7E49F53B1B1BF14500FBC3FF /* concatenate_swift_files.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = concatenate_swift_files.sh; sourceTree = "<group>"; };
+		7E49F53F1B1BF1FE00FBC3FF /* TegKeychain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TegKeychain.swift; sourceTree = "<group>"; };
+		7E49F5401B1BF1FE00FBC3FF /* TegKeychainAccessOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TegKeychainAccessOptions.swift; sourceTree = "<group>"; };
+		7E49F5411B1BF1FE00FBC3FF /* TegKeychainConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TegKeychainConstants.swift; sourceTree = "<group>"; };
+		7E49F5491B1BF25F00FBC3FF /* TegKeychainDistrib.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TegKeychainDistrib.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -73,6 +76,8 @@
 				2BCB00B11A8335740022C93A /* Default-568h@2x.png */,
 				2BCB008E1A83354D0022C93A /* keychain */,
 				2BCB00A41A83354D0022C93A /* keychainTests */,
+				7E49F5481B1BF22600FBC3FF /* Distrib */,
+				7E49F53A1B1BF13B00FBC3FF /* scripts */,
 				2BCB008D1A83354D0022C93A /* Products */,
 			);
 			sourceTree = "<group>";
@@ -89,7 +94,7 @@
 		2BCB008E1A83354D0022C93A /* keychain */ = {
 			isa = PBXGroup;
 			children = (
-				2BCB00B31A8335A20022C93A /* Lib */,
+				7E49F53E1B1BF1F000FBC3FF /* Lib */,
 				2BCB00911A83354D0022C93A /* AppDelegate.swift */,
 				2BCB00931A83354D0022C93A /* ViewController.swift */,
 				2BCB00951A83354D0022C93A /* Main.storyboard */,
@@ -125,14 +130,30 @@
 			name = "Supporting Files";
 			sourceTree = "<group>";
 		};
-		2BCB00B31A8335A20022C93A /* Lib */ = {
+		7E49F53A1B1BF13B00FBC3FF /* scripts */ = {
 			isa = PBXGroup;
 			children = (
-				2BCB00B41A8335AF0022C93A /* TegKeychain.swift */,
-				7E49F5351B1BE41B00FBC3FF /* TegKeychainAccessOptions.swift */,
-				2B48E3391A92F47800456D2F /* TegKeychainConstants.swift */,
+				7E49F53B1B1BF14500FBC3FF /* concatenate_swift_files.sh */,
 			);
-			name = Lib;
+			path = scripts;
+			sourceTree = "<group>";
+		};
+		7E49F53E1B1BF1F000FBC3FF /* Lib */ = {
+			isa = PBXGroup;
+			children = (
+				7E49F53F1B1BF1FE00FBC3FF /* TegKeychain.swift */,
+				7E49F5401B1BF1FE00FBC3FF /* TegKeychainAccessOptions.swift */,
+				7E49F5411B1BF1FE00FBC3FF /* TegKeychainConstants.swift */,
+			);
+			path = Lib;
+			sourceTree = "<group>";
+		};
+		7E49F5481B1BF22600FBC3FF /* Distrib */ = {
+			isa = PBXGroup;
+			children = (
+				7E49F5491B1BF25F00FBC3FF /* TegKeychainDistrib.swift */,
+			);
+			path = Distrib;
 			sourceTree = "<group>";
 		};
 /* End PBXGroup section */
@@ -145,6 +166,7 @@
 				2BCB00881A83354D0022C93A /* Sources */,
 				2BCB00891A83354D0022C93A /* Frameworks */,
 				2BCB008A1A83354D0022C93A /* Resources */,
+				7E49F53D1B1BF15900FBC3FF /* Combine swift files into single file */,
 			);
 			buildRules = (
 			);
@@ -218,6 +240,7 @@
 				2BCB00971A83354D0022C93A /* Main.storyboard in Resources */,
 				2BCB00B21A8335740022C93A /* Default-568h@2x.png in Resources */,
 				2BCB009C1A83354D0022C93A /* LaunchScreen.xib in Resources */,
+				7E49F53C1B1BF14500FBC3FF /* concatenate_swift_files.sh in Resources */,
 				2BCB00991A83354D0022C93A /* Images.xcassets in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
@@ -231,6 +254,23 @@
 		};
 /* End PBXResourcesBuildPhase section */
 
+/* Begin PBXShellScriptBuildPhase section */
+		7E49F53D1B1BF15900FBC3FF /* Combine swift files into single file */ = {
+			isa = PBXShellScriptBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			inputPaths = (
+			);
+			name = "Combine swift files into single file";
+			outputPaths = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+			shellPath = /bin/sh;
+			shellScript = "${SRCROOT}/scripts/concatenate_swift_files.sh ${SRCROOT}/keychain/Lib ${SRCROOT}/Distrib/TegKeychainDistrib.swift '//\\n// Keychain helper for iOS/Swift.\\n//\\n// https://github.com/exchangegroup/keychain-swift\\n//\\n// This file was automatically generated by combining multiple Swift source files.\\n//'";
+		};
+/* End PBXShellScriptBuildPhase section */
+
 /* Begin PBXSourcesBuildPhase section */
 		2BCB00881A83354D0022C93A /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
@@ -238,9 +278,9 @@
 			files = (
 				2BCB00941A83354D0022C93A /* ViewController.swift in Sources */,
 				2BCB00921A83354D0022C93A /* AppDelegate.swift in Sources */,
-				7E49F5361B1BE41B00FBC3FF /* TegKeychainAccessOptions.swift in Sources */,
-				2B48E33A1A92F47800456D2F /* TegKeychainConstants.swift in Sources */,
-				2BCB00B51A8335AF0022C93A /* TegKeychain.swift in Sources */,
+				7E49F5421B1BF1FE00FBC3FF /* TegKeychain.swift in Sources */,
+				7E49F5431B1BF1FE00FBC3FF /* TegKeychainAccessOptions.swift in Sources */,
+				7E49F5441B1BF1FE00FBC3FF /* TegKeychainConstants.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -248,9 +288,9 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				7E49F5381B1BEE0D00FBC3FF /* TegKeychainAccessOptions.swift in Sources */,
-				7E49F5371B1BEE0B00FBC3FF /* TegKeychain.swift in Sources */,
-				7E49F5391B1BEE0F00FBC3FF /* TegKeychainConstants.swift in Sources */,
+				7E49F5461B1BF20C00FBC3FF /* TegKeychainAccessOptions.swift in Sources */,
+				7E49F5451B1BF20A00FBC3FF /* TegKeychain.swift in Sources */,
+				7E49F5471B1BF20E00FBC3FF /* TegKeychainConstants.swift in Sources */,
 				2BCB00A81A83354D0022C93A /* keychainTests.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 0 - 0
keychain/TegKeychain.swift → keychain/Lib/TegKeychain.swift


+ 0 - 0
keychain/TegKeychainAccessOptions.swift → keychain/Lib/TegKeychainAccessOptions.swift


+ 0 - 0
keychain/TegKeychainConstants.swift → keychain/Lib/TegKeychainConstants.swift


+ 53 - 0
scripts/concatenate_swift_files.sh

@@ -0,0 +1,53 @@
+#!/bin/bash
+
+#
+#  Combines *.swift files into a single file.
+#
+#  Usage
+#  ------
+#
+#  ./combine_swift_files.sh source_dir destination_file [optional_header_text]
+#
+
+destination=$2
+headermessage=$3
+
+if [ "$#" -lt 2 ]
+then
+  echo "\nUsage:\n"
+  echo "   ./combine_swift_files.sh source_dir destination_file [optional_header_text]\n"
+  exit 1
+fi
+
+# Create empty destination file
+echo > "$destination";
+text=""
+destination_filename=$(basename "$destination")
+
+for swift in `find $1 ! -name "$destination_filename" -name "*.swift"`;
+do
+  filename=$(basename "$swift")
+
+  text="$text\n// ----------------------------";
+  text="$text\n//";
+  text="$text\n// ${filename}";
+  text="$text\n//";
+  text="$text\n// ----------------------------\n\n";
+
+  text="$text$(cat "${swift}";)\n\n";
+
+  echo "Combining $swift";
+done;
+
+# Add header message
+if [ -n "$headermessage" ]
+then
+  text="$headermessage\n\n$text"
+fi
+
+# Write to destination file
+echo -e "$text" > "$destination"
+
+echo -e "\nSwift files combined into $destination"
+
+