Skip to content

Commit

Permalink
Updated for Swift 3
Browse files Browse the repository at this point in the history
This was done using the migrator and small fixes afterwards. This does not adopt any of the new style guidlines.
  • Loading branch information
davbeck committed Jun 16, 2016
1 parent f2cbf84 commit 30f8a53
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
15 changes: 10 additions & 5 deletions UTIKit.xcodeproj/project.pbxproj
Expand Up @@ -202,7 +202,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = cockscomb.info;
TargetAttributes = {
09F886601A98D47E00ADF55F = {
Expand Down Expand Up @@ -341,6 +341,7 @@
PRODUCT_NAME = UTIKit;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
Expand Down Expand Up @@ -368,6 +369,7 @@
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -414,6 +416,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand Down Expand Up @@ -447,7 +450,7 @@
PRODUCT_NAME = UTIKit;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -467,7 +470,8 @@
PRODUCT_BUNDLE_IDENTIFIER = "info.cockscomb.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = UTIKit;
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -486,7 +490,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "info.cockscomb.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -501,7 +505,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "info.cockscomb.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
50 changes: 25 additions & 25 deletions UTIKit/UTI.swift
Expand Up @@ -64,17 +64,17 @@ public struct UTI: CustomStringConvertible, CustomDebugStringConvertible, Equata

// MARK: -

private static func UTIsForTagClass(tagClass: String, tag: String, conformingToUTI: UTI?) -> [UTI] {
private static func UTIsForTagClass(_ tagClass: String, tag: String, conformingToUTI: UTI?) -> [UTI] {
let conformingToUTIString: CFString? = conformingToUTI?.UTIString
guard let rawUTIs = UTTypeCreateAllIdentifiersForTag(tagClass, tag, conformingToUTIString)?.takeRetainedValue() else { return [] }
return (rawUTIs as NSArray as? [String] ?? []).map { UTI($0) }
}

public static func UTIsFromFilenameExtension(filenameExtension: String, conformingToUTI: UTI? = nil) -> [UTI] {
public static func UTIsFromFilenameExtension(_ filenameExtension: String, conformingToUTI: UTI? = nil) -> [UTI] {
return UTIsForTagClass(kUTTagClassFilenameExtension as String, tag: filenameExtension, conformingToUTI: conformingToUTI)
}

public static func UTIsFromMIMEType(MIMEType: String, conformingToUTI: UTI? = nil) -> [UTI] {
public static func UTIsFromMIMEType(_ MIMEType: String, conformingToUTI: UTI? = nil) -> [UTI] {
return UTIsForTagClass(kUTTagClassMIMEType as String, tag: MIMEType, conformingToUTI: conformingToUTI)
}

Expand All @@ -90,13 +90,13 @@ public struct UTI: CustomStringConvertible, CustomDebugStringConvertible, Equata

// MARK: - Tags

private func tagWithClass(tagClass: String) -> String? {
private func tagWithClass(_ tagClass: String) -> String? {
return UTTypeCopyPreferredTagWithClass(UTIString, tagClass)?.takeRetainedValue() as String?
}

@available(OSX, introduced=10.10)
@available(iOS, introduced=8.0)
private func tagsWithClass(tagClass: String) -> [String] {
@available(OSX, introduced:10.10)
@available(iOS, introduced:8.0)
private func tagsWithClass(_ tagClass: String) -> [String] {
guard let tags = UTTypeCopyAllTagsWithClass(UTIString, tagClass)?.takeRetainedValue() else { return [] }
return tags as NSArray as? [String] ?? []
}
Expand All @@ -105,8 +105,8 @@ public struct UTI: CustomStringConvertible, CustomDebugStringConvertible, Equata
return tagWithClass(kUTTagClassFilenameExtension as String)
}

@available(OSX, introduced=10.10)
@available(iOS, introduced=8.0)
@available(OSX, introduced:10.10)
@available(iOS, introduced:8.0)
public var filenameExtensions: [String] {
return tagsWithClass(kUTTagClassFilenameExtension as String)
}
Expand All @@ -115,8 +115,8 @@ public struct UTI: CustomStringConvertible, CustomDebugStringConvertible, Equata
return tagWithClass(kUTTagClassMIMEType as String)
}

@available(OSX, introduced=10.10)
@available(iOS, introduced=8.0)
@available(OSX, introduced:10.10)
@available(iOS, introduced:8.0)
public var MIMETypes: [String] {
return tagsWithClass(kUTTagClassMIMEType as String)
}
Expand All @@ -126,7 +126,7 @@ public struct UTI: CustomStringConvertible, CustomDebugStringConvertible, Equata
return tagWithClass(kUTTagClassNSPboardType as String)
}

@available(OSX, introduced=10.10)
@available(OSX, introduced:10.10)
public var pasteBoardTypes: [String] {
return tagsWithClass(kUTTagClassNSPboardType as String)
}
Expand All @@ -135,22 +135,22 @@ public struct UTI: CustomStringConvertible, CustomDebugStringConvertible, Equata
return tagWithClass(kUTTagClassOSType as String)
}

@available(OSX, introduced=10.10)
@available(OSX, introduced:10.10)
public var OSTypes: [String] {
return tagsWithClass(kUTTagClassOSType as String)
}
#endif

// MARK: - Status

@available(OSX, introduced=10.10)
@available(iOS, introduced=8.0)
@available(OSX, introduced:10.10)
@available(iOS, introduced:8.0)
public var isDeclared: Bool {
return UTTypeIsDeclared(UTIString)
}

@available(OSX, introduced=10.10)
@available(iOS, introduced=8.0)
@available(OSX, introduced:10.10)
@available(iOS, introduced:8.0)
public var isDynamic: Bool {
return UTTypeIsDynamic(UTIString)
}
Expand Down Expand Up @@ -191,9 +191,9 @@ public struct UTI: CustomStringConvertible, CustomDebugStringConvertible, Equata
return raw[kUTTypeIconFileKey] as? String
}

public var referenceURL: NSURL? {
public var referenceURL: URL? {
if let reference = raw[kUTTypeReferenceURLKey] as? String {
return NSURL(string: reference)
return URL(string: reference)
}
return nil
}
Expand All @@ -220,17 +220,17 @@ public struct UTI: CustomStringConvertible, CustomDebugStringConvertible, Equata
return Declaration(declaration: UTTypeCopyDeclaration(self.UTIString)?.takeRetainedValue() as [NSObject: AnyObject]? ?? [:])
}

public var declaringBundle: NSBundle? {
if let URL = UTTypeCopyDeclaringBundleURL(UTIString)?.takeRetainedValue() {
return NSBundle(URL: URL)
public var declaringBundle: Bundle? {
if let url = UTTypeCopyDeclaringBundleURL(UTIString)?.takeRetainedValue() {
return Bundle(url: url as URL)
}
return nil
}

public var iconFileURL: NSURL? {
public var iconFileURL: URL? {
if let iconFile = declaration.iconFile {
return self.declaringBundle?.URLForResource(iconFile, withExtension: nil) ??
self.declaringBundle?.URLForResource(iconFile, withExtension: "icns")
return self.declaringBundle?.urlForResource(iconFile, withExtension: nil) ??
self.declaringBundle?.urlForResource(iconFile, withExtension: "icns")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions UTIKitTests/UTITests.swift
Expand Up @@ -90,11 +90,11 @@ class UTITests: XCTestCase {
let pages = UTI(filenameExtension: "pages")!
XCTAssertTrue(pages.declaration.exportedTypeDeclarations.isEmpty)
XCTAssertTrue(pages.declaration.importedTypeDeclarations.isEmpty)
XCTAssertEqual(pages.declaration.identifier!, "com.apple.iWork.Pages.pages")
XCTAssertEqual(pages.declaration.identifier?.lowercased(), "com.apple.iwork.pages.pages")
XCTAssertNotNil(pages.declaration.tagSpecification)
XCTAssertEqual(pages.declaration.conformsTo, [ UTI(kUTTypePackage as String), UTI(kUTTypeCompositeContent as String) ])
XCTAssertNil(pages.declaration.iconFile)
XCTAssertEqual(pages.declaration.referenceURL!, NSURL(string: "http://www.apple.com/iwork/pages/")!)
XCTAssertEqual(pages.declaration.referenceURL!, URL(string: "http://www.apple.com/iwork/pages/")!)
XCTAssertNil(pages.declaration.version)
}

Expand Down

0 comments on commit 30f8a53

Please sign in to comment.