Skip to content

Commit

Permalink
Merge pull request #13 from nitrag/swift-5
Browse files Browse the repository at this point in the history
Swift 5
  • Loading branch information
nitrag authored Nov 14, 2019
2 parents 9e883c2 + 07fab9c commit c244075
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 37 deletions.
39 changes: 29 additions & 10 deletions Icomoon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 48;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -99,7 +99,7 @@
8FFB56221C2D7BFB00D2BE62 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0800;
LastUpgradeCheck = 1100;
ORGANIZATIONNAME = Optonaut;
TargetAttributes = {
8FFB562A1C2D7BFB00D2BE62 = {
Expand All @@ -109,11 +109,12 @@
};
};
buildConfigurationList = 8FFB56251C2D7BFB00D2BE62 /* Build configuration list for PBXProject "Icomoon" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
compatibilityVersion = "Xcode 8.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 8FFB56211C2D7BFB00D2BE62;
productRefGroup = 8FFB562C1C2D7BFB00D2BE62 /* Products */;
Expand Down Expand Up @@ -154,18 +155,27 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
BITCODE_GENERATION_MODE = bitcode;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
CLANG_CXX_LIBRARY = "compiler-default";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -196,7 +206,7 @@
OTHER_CFLAGS = "-fembed-bitcode";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -208,18 +218,27 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
BITCODE_GENERATION_MODE = bitcode;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
CLANG_CXX_LIBRARY = "compiler-default";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -243,7 +262,7 @@
OTHER_CFLAGS = "-fembed-bitcode";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -270,8 +289,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3;
TARGETED_DEVICE_FAMILY = 1;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand All @@ -294,8 +313,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.optonaut.Icomoon;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
6 changes: 1 addition & 5 deletions Icomoon.xcodeproj/xcshareddata/xcschemes/Icomoon.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "1100"
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:Icomoon.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
48 changes: 29 additions & 19 deletions Icomoon/Icomoon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@ import UIKit
private class FontLoader {
class func loadFont() {
let bundle = Bundle(for: FontLoader.self)
let fontURL = bundle.url(forResource: "font", withExtension: "ttf")!
let data = try! Data(contentsOf: fontURL)

if let provider = CGDataProvider(data: data as CFData) {
let fontURL = bundle.url(forResource: "font", withExtension: "ttf")!
guard
let data = try? Data(contentsOf: fontURL),
let provider = CGDataProvider(data: data as CFData),
let font = CGFont(provider)

var error: Unmanaged<CFError>?
if !CTFontManagerRegisterGraphicsFont(font, &error) {
let errorDescription: CFString = CFErrorCopyDescription(error!.takeUnretainedValue())
let nsError = error!.takeUnretainedValue() as AnyObject as! NSError
NSException(name: NSExceptionName.internalInconsistencyException, reason: errorDescription as String, userInfo: [NSUnderlyingErrorKey: nsError]).raise()
}
else { return }

var error: Unmanaged<CFError>?
if !CTFontManagerRegisterGraphicsFont(font, &error) {
let errorDescription: CFString = CFErrorCopyDescription(error!.takeUnretainedValue())
let nsError = error!.takeUnretainedValue() as AnyObject as! NSError
NSException(name: NSExceptionName.internalInconsistencyException, reason: errorDescription as String, userInfo: [NSUnderlyingErrorKey: nsError]).raise()
}

}
}

public extension UIFont {
private static var _loaded = false

public static func iconOfSize(_ fontSize: CGFloat) -> UIFont {
static func iconOfSize(_ fontSize: CGFloat) -> UIFont {
if !_loaded {
if UIFont.fontNames(forFamilyName: Font.FontName).count == 0 {
FontLoader.loadFont()
Expand All @@ -43,14 +45,14 @@ public extension UIFont {
}

public extension UIImage {
public static func iconWithName(_ name: Icon, textColor: UIColor, fontSize: CGFloat, offset: CGSize = CGSize.zero) -> UIImage {
static func iconWithName(_ name: Icon, textColor: UIColor, fontSize: CGFloat, offset: CGSize = CGSize.zero) -> UIImage {
let paragraph = NSMutableParagraphStyle()
paragraph.lineBreakMode = .byWordWrapping
paragraph.alignment = .center
let attributes = [
NSFontAttributeName: UIFont.iconOfSize(fontSize),
NSForegroundColorAttributeName: textColor,
NSParagraphStyleAttributeName: paragraph
NSAttributedString.Key.font: UIFont.iconOfSize(fontSize),
NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.paragraphStyle: paragraph
]
let attributedString = NSAttributedString(string: String.iconWithName(name) as String, attributes: attributes)
let stringSize = sizeOfAttributeString(attributedString)
Expand All @@ -61,15 +63,23 @@ public extension UIImage {
UIGraphicsEndImageContext()
return image!
}
public static func icomoonIcon(name: Icon, textColor: UIColor, size: CGSize, backgroundColor: UIColor = UIColor.clear) -> UIImage {
static func icomoonIcon(name: Icon, textColor: UIColor, size: CGSize, backgroundColor: UIColor = UIColor.clear) -> UIImage {
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = NSTextAlignment.center

// Taken from FontAwesome.io's Fixed Width Icon CSS
let fontAspectRatio: CGFloat = 1.28571429

let fontSize = min(size.width / fontAspectRatio, size.height)
let attributedString = NSAttributedString(string: String.iconWithName(name) as String, attributes: [NSFontAttributeName: UIFont.iconOfSize(fontSize), NSForegroundColorAttributeName: textColor, NSBackgroundColorAttributeName: backgroundColor, NSParagraphStyleAttributeName: paragraph])
let attributedString = NSAttributedString(
string: String.iconWithName(name) as String,
attributes: [
NSAttributedString.Key.font: UIFont.iconOfSize(fontSize),
NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: backgroundColor,
NSAttributedString.Key.paragraphStyle: paragraph
]
)
UIGraphicsBeginImageContextWithOptions(size, false , 0.0)
attributedString.draw(in: CGRect(x: 0, y: (size.height - fontSize) / 2, width: size.width, height: fontSize))
let image = UIGraphicsGetImageFromCurrentImageContext()
Expand All @@ -79,8 +89,8 @@ public extension UIImage {
}

public extension String {
public static func iconWithName(_ name: Icon) -> String {
return name.rawValue.substring(to: name.rawValue.characters.index(name.rawValue.startIndex, offsetBy: 1))
static func iconWithName(_ name: Icon) -> String {
return String(name.rawValue[..<name.rawValue.index(name.rawValue.startIndex, offsetBy: 1)])
}
}

Expand Down
2 changes: 1 addition & 1 deletion Icomoon/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>2.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ Add `Icomoon.framework`

### Strip Architectures

In order to submit to App Store, you'll need to automatically strip unsupported architectures (i386 simulator). Add this "Run Script" to you Build Phases, AFTER *Embed Frameworks*, or as the final entry.
![](https://imgur.com/a/43bb3Dh.jpg)

![](http://i.imgur.com/gmXJXPg.jpg)
In order to submit to App Store, you'll need to automatically strip unsupported architectures (i386 simulator). Add this "Run Script" to you Build Phases, AFTER *Embed Frameworks*, or as the final entry.

```
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
Expand Down

0 comments on commit c244075

Please sign in to comment.