Skip to content

iosdevzone/enumtool

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
bin
 
 
 
 
 
 
 
 
 
 
 
 
 
 

enumtool

A command line tool to wrap Cocoa constants in Swift enums.

Usage Example

Recently I was working on some code that used the Keychain, part of the Security framework. I changed into the Headers directory of the Security framework and used the following commands to extract a subset of the constants (the valid values for the kSecAttrAccessible attribute)from that file.

grep '^extern CFTypeRef kSecAttrAccessible' SecItem.h | awk '{ print $3; }' > ~/Documents/src/enumtool/demo/SecAttrAcessible.txt

I edit the file to remove kSecAttrAccessible attribute itself, and then I ran enumtool as follows.

enumtool -i SecAttrAccessible.txt -n Accessible -r String -o Accessible.swift

The result was the following Swift file.

public enum Accessible : RawRepresentable, Printable {
	case , WhenUnlocked, AfterFirstUnlock, Always, WhenPasscodeSetThisDeviceOnly, WhenUnlockedThisDeviceOnly, AfterFirstUnlockThisDeviceOnly, AlwaysThisDeviceOnly
	
	public static let allValues: [Accessible] = [, WhenUnlocked, AfterFirstUnlock, Always, WhenPasscodeSetThisDeviceOnly, WhenUnlockedThisDeviceOnly, AfterFirstUnlockThisDeviceOnly, AlwaysThisDeviceOnly]
	
	public init?(rawValue: String) {
		if rawValue == String(kSecAttrAccessible) {
			self = 
		}
		else if rawValue == String(kSecAttrAccessibleWhenUnlocked) {
			self = WhenUnlocked
		}
		else if rawValue == String(kSecAttrAccessibleAfterFirstUnlock) {
			self = AfterFirstUnlock
		}
		else if rawValue == String(kSecAttrAccessibleAlways) {
			self = Always
		}
		else if rawValue == String(kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly) {
			self = WhenPasscodeSetThisDeviceOnly
		}
		else if rawValue == String(kSecAttrAccessibleWhenUnlockedThisDeviceOnly) {
			self = WhenUnlockedThisDeviceOnly
		}
		else if rawValue == String(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly) {
			self = AfterFirstUnlockThisDeviceOnly
		}
		else if rawValue == String(kSecAttrAccessibleAlwaysThisDeviceOnly) {
			self = AlwaysThisDeviceOnly
		}
		else {
			return nil
		}
	}
	
	public var rawValue: String {
		switch self {
			case : return String(kSecAttrAccessible)
			case WhenUnlocked: return String(kSecAttrAccessibleWhenUnlocked)
			case AfterFirstUnlock: return String(kSecAttrAccessibleAfterFirstUnlock)
			case Always: return String(kSecAttrAccessibleAlways)
			case WhenPasscodeSetThisDeviceOnly: return String(kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly)
			case WhenUnlockedThisDeviceOnly: return String(kSecAttrAccessibleWhenUnlockedThisDeviceOnly)
			case AfterFirstUnlockThisDeviceOnly: return String(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly)
			case AlwaysThisDeviceOnly: return String(kSecAttrAccessibleAlwaysThisDeviceOnly)
		}
	}
	
	public var description : String {
		switch self {
		case : return ""
		case WhenUnlocked: return "WhenUnlocked"
		case AfterFirstUnlock: return "AfterFirstUnlock"
		case Always: return "Always"
		case WhenPasscodeSetThisDeviceOnly: return "WhenPasscodeSetThisDeviceOnly"
		case WhenUnlockedThisDeviceOnly: return "WhenUnlockedThisDeviceOnly"
		case AfterFirstUnlockThisDeviceOnly: return "AfterFirstUnlockThisDeviceOnly"
		case AlwaysThisDeviceOnly: return "AlwaysThisDeviceOnly"
		}
	}
}

About

A command line tool to wrap Cocoa constants in Swift enums.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages