From 3892d9cc0a263a6530bc37ceaa60d3e75d262ead Mon Sep 17 00:00:00 2001 From: Enrique Garcia Date: Sun, 7 Mar 2021 16:04:27 +0100 Subject: [PATCH 1/8] update to swift 5 and fix compilation #72 + also update Xcode recommended settings --- Classes/ExpandableLabel.swift | 8 ++++++-- ExpandableLabel.xcodeproj/project.pbxproj | 15 +++++++++++---- .../xcschemes/ExpandableLabel.xcscheme | 6 ------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Classes/ExpandableLabel.swift b/Classes/ExpandableLabel.swift index 24463d3..25c726b 100644 --- a/Classes/ExpandableLabel.swift +++ b/Classes/ExpandableLabel.swift @@ -233,7 +233,8 @@ extension ExpandableLabel { let lineTextWithAddedLink = NSMutableAttributedString(attributedString: lineTextWithLastWordRemoved) if let ellipsis = self.ellipsis { lineTextWithAddedLink.append(ellipsis) - lineTextWithAddedLink.append(NSAttributedString(string: " ", attributes: [.font: self.font])) + lineTextWithAddedLink.append(NSAttributedString(string: " ", + attributes: [.font: (self.font ?? UIFont.preferredFont(forTextStyle: .body))])) } lineTextWithAddedLink.append(linkName) let fits = self.textFitsWidth(lineTextWithAddedLink) @@ -261,7 +262,8 @@ extension ExpandableLabel { let linkText = NSMutableAttributedString() if let ellipsis = self.ellipsis { linkText.append(ellipsis) - linkText.append(NSAttributedString(string: " ", attributes: [.font: self.font])) + linkText.append(NSAttributedString(string: " ", + attributes: [.font: (self.font ?? UIFont.preferredFont(forTextStyle: .body))])) } linkText.append(linkName) @@ -546,6 +548,8 @@ extension UILabel { return 1.0 case .left, .natural, .justified: return 0.0 + @unknown default: + fatalError() } } } diff --git a/ExpandableLabel.xcodeproj/project.pbxproj b/ExpandableLabel.xcodeproj/project.pbxproj index f18e94d..13357a7 100644 --- a/ExpandableLabel.xcodeproj/project.pbxproj +++ b/ExpandableLabel.xcodeproj/project.pbxproj @@ -89,7 +89,7 @@ 1B0D8A3B1F3AAA50004142A4 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1240; TargetAttributes = { 1B0D8A431F3AAA50004142A4 = { CreatedOnToolsVersion = 8.3.3; @@ -100,10 +100,11 @@ }; buildConfigurationList = 1B0D8A3E1F3AAA50004142A4 /* Build configuration list for PBXProject "ExpandableLabel" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = 1B0D8A3A1F3AAA50004142A4; productRefGroup = 1B0D8A451F3AAA50004142A4 /* Products */; @@ -151,6 +152,7 @@ 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_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -158,8 +160,10 @@ 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_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -211,6 +215,7 @@ 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_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -218,8 +223,10 @@ 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_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -264,7 +271,7 @@ PRODUCT_BUNDLE_IDENTIFIER = de.apploft.ExpandableLabel; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -282,7 +289,7 @@ PRODUCT_BUNDLE_IDENTIFIER = de.apploft.ExpandableLabel; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/ExpandableLabel.xcodeproj/xcshareddata/xcschemes/ExpandableLabel.xcscheme b/ExpandableLabel.xcodeproj/xcshareddata/xcschemes/ExpandableLabel.xcscheme index 90fca38..724583a 100644 --- a/ExpandableLabel.xcodeproj/xcshareddata/xcschemes/ExpandableLabel.xcscheme +++ b/ExpandableLabel.xcodeproj/xcshareddata/xcschemes/ExpandableLabel.xcscheme @@ -26,18 +26,14 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" shouldUseLaunchSchemeArgsEnv = "YES"> - - - - Date: Mon, 8 Mar 2021 00:20:18 +0100 Subject: [PATCH 2/8] add support for Swift Package Manager (SPM) --- ExpandableLabel.xcodeproj/project.pbxproj | 2 ++ .../xcschemes/ExpandableLabel.xcscheme | 2 +- Package.swift | 22 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Package.swift diff --git a/ExpandableLabel.xcodeproj/project.pbxproj b/ExpandableLabel.xcodeproj/project.pbxproj index 13357a7..0e84cdf 100644 --- a/ExpandableLabel.xcodeproj/project.pbxproj +++ b/ExpandableLabel.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 1B0D8A441F3AAA50004142A4 /* ExpandableLabel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ExpandableLabel.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 1B0D8A501F3AAA6C004142A4 /* ExpandableLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpandableLabel.swift; sourceTree = ""; }; 1B0D8A511F3AAA6C004142A4 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + F685D23D232A593F0000133D /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -30,6 +31,7 @@ 1B0D8A3A1F3AAA50004142A4 = { isa = PBXGroup; children = ( + F685D23D232A593F0000133D /* Package.swift */, 1B0D8A4F1F3AAA6C004142A4 /* Classes */, 1B0D8A451F3AAA50004142A4 /* Products */, ); diff --git a/ExpandableLabel.xcodeproj/xcshareddata/xcschemes/ExpandableLabel.xcscheme b/ExpandableLabel.xcodeproj/xcshareddata/xcschemes/ExpandableLabel.xcscheme index 724583a..5c1c868 100644 --- a/ExpandableLabel.xcodeproj/xcshareddata/xcschemes/ExpandableLabel.xcscheme +++ b/ExpandableLabel.xcodeproj/xcshareddata/xcschemes/ExpandableLabel.xcscheme @@ -1,6 +1,6 @@ Date: Tue, 30 Mar 2021 19:06:52 +0200 Subject: [PATCH 3/8] add demo project to test support for Swift Package Manager (SPM) --- .../project.pbxproj | 344 ++++++++++++++++++ .../ExpandableLabelDemoSPM/AppDelegate.swift | 61 ++++ .../Base.lproj/LaunchScreen.xib | 41 +++ .../Base.lproj/Main.storyboard | 77 ++++ .../ExpandableCell.swift | 36 ++ .../AppIcon.appiconset/Contents.json | 38 ++ .../ExpandableLabelDemoSPM/Info.plist | 42 +++ .../ViewController.swift | 168 +++++++++ 8 files changed, 807 insertions(+) create mode 100644 ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj create mode 100644 ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/AppDelegate.swift create mode 100644 ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/LaunchScreen.xib create mode 100644 ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/Main.storyboard create mode 100644 ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/ExpandableCell.swift create mode 100644 ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Info.plist create mode 100644 ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/ViewController.swift diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj new file mode 100644 index 0000000..62eafbd --- /dev/null +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj @@ -0,0 +1,344 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + BF0468121B44121F009EC2F9 /* ExpandableLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0468111B44121F009EC2F9 /* ExpandableLabel.swift */; }; + BF38D1C81B42EE3E000091FD /* ExpandableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF38D1C71B42EE3E000091FD /* ExpandableCell.swift */; }; + BF4342A01B416FDD002FDE1F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF43429F1B416FDD002FDE1F /* AppDelegate.swift */; }; + BF4342A21B416FDD002FDE1F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF4342A11B416FDD002FDE1F /* ViewController.swift */; }; + BF4342A51B416FDD002FDE1F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF4342A31B416FDD002FDE1F /* Main.storyboard */; }; + BF4342A71B416FDD002FDE1F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BF4342A61B416FDD002FDE1F /* Images.xcassets */; }; + BF4342AA1B416FDD002FDE1F /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = BF4342A81B416FDD002FDE1F /* LaunchScreen.xib */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + BF0468111B44121F009EC2F9 /* ExpandableLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpandableLabel.swift; sourceTree = ""; }; + BF38D1C71B42EE3E000091FD /* ExpandableCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpandableCell.swift; sourceTree = ""; }; + BF43429A1B416FDD002FDE1F /* ExpandableLabelDemoSPM.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ExpandableLabelDemoSPM.app; sourceTree = BUILT_PRODUCTS_DIR; }; + BF43429E1B416FDD002FDE1F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + BF43429F1B416FDD002FDE1F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + BF4342A11B416FDD002FDE1F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + BF4342A41B416FDD002FDE1F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + BF4342A61B416FDD002FDE1F /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + BF4342A91B416FDD002FDE1F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + BF4342971B416FDD002FDE1F /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + BF0468101B44121F009EC2F9 /* Classes */ = { + isa = PBXGroup; + children = ( + BF0468111B44121F009EC2F9 /* ExpandableLabel.swift */, + ); + name = Classes; + path = ../../Classes; + sourceTree = ""; + }; + BF4342911B416FDD002FDE1F = { + isa = PBXGroup; + children = ( + BF43429C1B416FDD002FDE1F /* ExpandableLabelDemoSPM */, + BF43429B1B416FDD002FDE1F /* Products */, + ); + sourceTree = ""; + }; + BF43429B1B416FDD002FDE1F /* Products */ = { + isa = PBXGroup; + children = ( + BF43429A1B416FDD002FDE1F /* ExpandableLabelDemoSPM.app */, + ); + name = Products; + sourceTree = ""; + }; + BF43429C1B416FDD002FDE1F /* ExpandableLabelDemoSPM */ = { + isa = PBXGroup; + children = ( + BF0468101B44121F009EC2F9 /* Classes */, + BF43429F1B416FDD002FDE1F /* AppDelegate.swift */, + BF4342A11B416FDD002FDE1F /* ViewController.swift */, + BF38D1C71B42EE3E000091FD /* ExpandableCell.swift */, + BF4342A31B416FDD002FDE1F /* Main.storyboard */, + BF4342A61B416FDD002FDE1F /* Images.xcassets */, + BF4342A81B416FDD002FDE1F /* LaunchScreen.xib */, + BF43429D1B416FDD002FDE1F /* Supporting Files */, + ); + path = ExpandableLabelDemoSPM; + sourceTree = ""; + }; + BF43429D1B416FDD002FDE1F /* Supporting Files */ = { + isa = PBXGroup; + children = ( + BF43429E1B416FDD002FDE1F /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + BF4342991B416FDD002FDE1F /* ExpandableLabelDemoSPM */ = { + isa = PBXNativeTarget; + buildConfigurationList = BF4342B91B416FDD002FDE1F /* Build configuration list for PBXNativeTarget "ExpandableLabelDemoSPM" */; + buildPhases = ( + BF4342961B416FDD002FDE1F /* Sources */, + BF4342971B416FDD002FDE1F /* Frameworks */, + BF4342981B416FDD002FDE1F /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ExpandableLabelDemoSPM; + productName = ExpandableLabelDemo; + productReference = BF43429A1B416FDD002FDE1F /* ExpandableLabelDemoSPM.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + BF4342921B416FDD002FDE1F /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftMigration = 0700; + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 1010; + ORGANIZATIONNAME = "Mathias Koehnke"; + TargetAttributes = { + BF4342991B416FDD002FDE1F = { + CreatedOnToolsVersion = 6.3.2; + LastSwiftMigration = 0900; + }; + }; + }; + buildConfigurationList = BF4342951B416FDD002FDE1F /* Build configuration list for PBXProject "ExpandableLabelDemoSPM" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + English, + en, + Base, + ); + mainGroup = BF4342911B416FDD002FDE1F; + productRefGroup = BF43429B1B416FDD002FDE1F /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + BF4342991B416FDD002FDE1F /* ExpandableLabelDemoSPM */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + BF4342981B416FDD002FDE1F /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + BF4342A51B416FDD002FDE1F /* Main.storyboard in Resources */, + BF4342AA1B416FDD002FDE1F /* LaunchScreen.xib in Resources */, + BF4342A71B416FDD002FDE1F /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + BF4342961B416FDD002FDE1F /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + BF0468121B44121F009EC2F9 /* ExpandableLabel.swift in Sources */, + BF4342A21B416FDD002FDE1F /* ViewController.swift in Sources */, + BF4342A01B416FDD002FDE1F /* AppDelegate.swift in Sources */, + BF38D1C81B42EE3E000091FD /* ExpandableCell.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + BF4342A31B416FDD002FDE1F /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + BF4342A41B416FDD002FDE1F /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + BF4342A81B416FDD002FDE1F /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + BF4342A91B416FDD002FDE1F /* Base */, + ); + name = LaunchScreen.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + BF4342B71B416FDD002FDE1F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + 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; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + 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", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + BF4342B81B416FDD002FDE1F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + 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; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + 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; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + BF4342BA1B416FDD002FDE1F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = ExpandableLabelDemoSPM/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "de.apploft.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.2; + }; + name = Debug; + }; + BF4342BB1B416FDD002FDE1F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = ExpandableLabelDemoSPM/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "de.apploft.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.2; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + BF4342951B416FDD002FDE1F /* Build configuration list for PBXProject "ExpandableLabelDemoSPM" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + BF4342B71B416FDD002FDE1F /* Debug */, + BF4342B81B416FDD002FDE1F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + BF4342B91B416FDD002FDE1F /* Build configuration list for PBXNativeTarget "ExpandableLabelDemoSPM" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + BF4342BA1B416FDD002FDE1F /* Debug */, + BF4342BB1B416FDD002FDE1F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = BF4342921B416FDD002FDE1F /* Project object */; +} diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/AppDelegate.swift b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/AppDelegate.swift new file mode 100644 index 0000000..0b55a52 --- /dev/null +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/AppDelegate.swift @@ -0,0 +1,61 @@ +// +// AppDelegate.swift +// +// Copyright (c) 2015 apploft. GmbH +// +// 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. + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + func applicationWillResignActive(_ application: UIApplication) { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(_ application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(_ application: UIApplication) { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(_ application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(_ application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/LaunchScreen.xib b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/LaunchScreen.xib new file mode 100644 index 0000000..4795ec0 --- /dev/null +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/Main.storyboard b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/Main.storyboard new file mode 100644 index 0000000..e73040c --- /dev/null +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/Main.storyboard @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/ExpandableCell.swift b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/ExpandableCell.swift new file mode 100644 index 0000000..5d29401 --- /dev/null +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/ExpandableCell.swift @@ -0,0 +1,36 @@ +// +// ExpandableCell.swift +// +// Copyright (c) 2015 apploft. GmbH +// +// 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. + +import UIKit + +class ExpandableCell : UITableViewCell { + + + @IBOutlet weak var expandableLabel: ExpandableLabel! + + override func prepareForReuse() { + super.prepareForReuse() + expandableLabel.collapsed = true + expandableLabel.text = nil + } +} \ No newline at end of file diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Images.xcassets/AppIcon.appiconset/Contents.json b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..118c98f --- /dev/null +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,38 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Info.plist b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Info.plist new file mode 100644 index 0000000..cb2b8b8 --- /dev/null +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Info.plist @@ -0,0 +1,42 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + Label Demo + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/ViewController.swift b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/ViewController.swift new file mode 100644 index 0000000..954a5a1 --- /dev/null +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/ViewController.swift @@ -0,0 +1,168 @@ +// +// ViewController.swift +// +// Copyright (c) 2015 apploft. GmbH +// +// 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. + +import UIKit + +class ViewController: UITableViewController, ExpandableLabelDelegate { + + let numberOfCells : NSInteger = 12 + var states : Array! + + override func viewDidLoad() { + super.viewDidLoad() + + states = [Bool](repeating: true, count: numberOfCells) + tableView.estimatedRowHeight = 44 + tableView.rowHeight = UITableView.automaticDimension + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + tableView.reloadData() + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let currentSource = preparedSources()[indexPath.row] + + let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! ExpandableCell + cell.expandableLabel.delegate = self + + cell.expandableLabel.setLessLinkWith(lessLink: "Close", attributes: [.foregroundColor:UIColor.red], position: currentSource.textAlignment) + + cell.layoutIfNeeded() + + cell.expandableLabel.shouldCollapse = true + cell.expandableLabel.textReplacementType = currentSource.textReplacementType + cell.expandableLabel.numberOfLines = currentSource.numberOfLines + cell.expandableLabel.collapsed = states[indexPath.row] + cell.expandableLabel.text = currentSource.text + + return cell + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return states.count + } + + func preparedSources() -> [(text: String, textReplacementType: ExpandableLabel.TextReplacementType, numberOfLines: Int, textAlignment: NSTextAlignment)] { + return [(loremIpsumText(), .word, 3, .left), + (textWithNewLinesInCollapsedLine(), .word, 2, .center), + (textWithLongWordInCollapsedLine(), .character, 1, .right), + (textWithVeryLongWords(), .character, 1, .left), + (loremIpsumText(), .word, 4, .center), + (loremIpsumText(), .character, 3, .right), + (loremIpsumText(), .word, 2, .left), + (loremIpsumText(), .character, 5, .center), + (loremIpsumText(), .word, 3, .right), + (loremIpsumText(), .character, 1, .left), + (textWithShortWordsPerLine(), .character, 3, .center), + (textEmojis(), .character, 3, .left)] + } + + + func loremIpsumText() -> String { + return "On third line our text need be collapsed because we have ordinary text, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." + } + + func textWithNewLinesInCollapsedLine() -> String { + return "When u had new line specialChars \n More not appeared eirmod\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n tempor invidunt ut\n\n\n\n labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." + } + + func textWithLongWordInCollapsedLine() -> String { + return "When u had long word which not entered in one line More not appeared FooBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaR tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." + } + + func textWithVeryLongWords() -> String { + return "FooBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaR FooBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaR FooBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaR FooBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaR Will show first line and will increase touch area for more voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." + } + + func textWithShortWordsPerLine() -> String { + return "A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN" + } + + func textEmojis() -> String { + return "πŸ˜‚πŸ˜„πŸ˜ƒπŸ˜ŠπŸ˜πŸ˜—πŸ˜œπŸ˜…πŸ˜“β˜ΊοΈπŸ˜ΆπŸ€¦πŸ˜’πŸ˜πŸ˜ŸπŸ˜΅πŸ™πŸ€”πŸ€“β˜ΉοΈπŸ™„πŸ˜‘πŸ˜«πŸ˜±πŸ™‚πŸ˜§πŸ€΅πŸ˜ΆπŸ‘₯πŸ‘©β€β€οΈβ€πŸ‘©πŸ’–πŸ‘¨β€β€οΈβ€πŸ’‹β€πŸ‘¨πŸ’πŸ‘©β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ‘¦πŸ‘€πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦πŸ‘©β€β€οΈβ€πŸ‘©πŸ—¨πŸ•΄πŸ‘©β€β€οΈβ€πŸ’‹β€πŸ‘©πŸ‘§β˜ΉοΈπŸ˜ πŸ˜€πŸ˜†πŸ’šπŸ™„πŸ€’πŸ’‹πŸ˜ΏπŸ‘„" + } + + // + // MARK: ExpandableLabel Delegate + // + + func willExpandLabel(_ label: ExpandableLabel) { + tableView.beginUpdates() + } + + func didExpandLabel(_ label: ExpandableLabel) { + let point = label.convert(CGPoint.zero, to: tableView) + if let indexPath = tableView.indexPathForRow(at: point) as IndexPath? { + states[indexPath.row] = false + DispatchQueue.main.async { [weak self] in + self?.tableView.scrollToRow(at: indexPath, at: .top, animated: true) + } + } + tableView.endUpdates() + } + + func willCollapseLabel(_ label: ExpandableLabel) { + tableView.beginUpdates() + } + + func didCollapseLabel(_ label: ExpandableLabel) { + let point = label.convert(CGPoint.zero, to: tableView) + if let indexPath = tableView.indexPathForRow(at: point) as IndexPath? { + states[indexPath.row] = true + DispatchQueue.main.async { [weak self] in + self?.tableView.scrollToRow(at: indexPath, at: .top, animated: true) + } + } + tableView.endUpdates() + } +} + +extension String { + + func specialPriceAttributedStringWith(_ color: UIColor) -> NSMutableAttributedString { + let attributes = [NSAttributedString.Key.strikethroughStyle: NSNumber(value: NSUnderlineStyle.single.rawValue as Int), + .foregroundColor: color, .font: fontForPrice()] + return NSMutableAttributedString(attributedString: NSAttributedString(string: self, attributes: attributes)) + } + + func priceAttributedStringWith(_ color: UIColor) -> NSAttributedString { + let attributes = [NSAttributedString.Key.foregroundColor: color, .font: fontForPrice()] + + return NSAttributedString(string: self, attributes: attributes) + } + + func priceAttributedString(_ color: UIColor) -> NSAttributedString { + let attributes = [NSAttributedString.Key.foregroundColor: color] + + return NSAttributedString(string: self, attributes: attributes) + } + + fileprivate func fontForPrice() -> UIFont { + return UIFont(name: "Helvetica-Neue", size: 13) ?? UIFont() + } +} + + + From 546e6eff024107324f604dc675f8daafe73ca080 Mon Sep 17 00:00:00 2001 From: Enrique Garcia Date: Tue, 30 Mar 2021 19:23:48 +0200 Subject: [PATCH 4/8] migrate ExpandableLabelDemo to swift 5 and update recommended settings. --- .../ExpandableLabelDemo.xcodeproj/project.pbxproj | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ExpandableLabelDemo/ExpandableLabelDemo.xcodeproj/project.pbxproj b/ExpandableLabelDemo/ExpandableLabelDemo.xcodeproj/project.pbxproj index 9073ff9..684e4b8 100644 --- a/ExpandableLabelDemo/ExpandableLabelDemo.xcodeproj/project.pbxproj +++ b/ExpandableLabelDemo/ExpandableLabelDemo.xcodeproj/project.pbxproj @@ -115,18 +115,18 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 1010; + LastUpgradeCheck = 1240; ORGANIZATIONNAME = "Mathias Koehnke"; TargetAttributes = { BF4342991B416FDD002FDE1F = { CreatedOnToolsVersion = 6.3.2; - LastSwiftMigration = 0900; + LastSwiftMigration = 1240; }; }; }; buildConfigurationList = BF4342951B416FDD002FDE1F /* Build configuration list for PBXProject "ExpandableLabelDemo" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -193,6 +193,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -211,6 +212,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -248,6 +250,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -266,6 +269,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -300,7 +304,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "de.apploft.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -312,7 +316,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "de.apploft.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; From 8898d6990fad9d87db50f8532e9a3385f4265d82 Mon Sep 17 00:00:00 2001 From: Enrique Garcia Date: Tue, 30 Mar 2021 19:25:42 +0200 Subject: [PATCH 5/8] remove local file ExpandableLabel from ExpandableLabelDemoSPM project --- .../project.pbxproj | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj index 62eafbd..64e1ba2 100644 --- a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - BF0468121B44121F009EC2F9 /* ExpandableLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0468111B44121F009EC2F9 /* ExpandableLabel.swift */; }; BF38D1C81B42EE3E000091FD /* ExpandableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF38D1C71B42EE3E000091FD /* ExpandableCell.swift */; }; BF4342A01B416FDD002FDE1F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF43429F1B416FDD002FDE1F /* AppDelegate.swift */; }; BF4342A21B416FDD002FDE1F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF4342A11B416FDD002FDE1F /* ViewController.swift */; }; @@ -17,7 +16,6 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - BF0468111B44121F009EC2F9 /* ExpandableLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpandableLabel.swift; sourceTree = ""; }; BF38D1C71B42EE3E000091FD /* ExpandableCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpandableCell.swift; sourceTree = ""; }; BF43429A1B416FDD002FDE1F /* ExpandableLabelDemoSPM.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ExpandableLabelDemoSPM.app; sourceTree = BUILT_PRODUCTS_DIR; }; BF43429E1B416FDD002FDE1F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -39,15 +37,6 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - BF0468101B44121F009EC2F9 /* Classes */ = { - isa = PBXGroup; - children = ( - BF0468111B44121F009EC2F9 /* ExpandableLabel.swift */, - ); - name = Classes; - path = ../../Classes; - sourceTree = ""; - }; BF4342911B416FDD002FDE1F = { isa = PBXGroup; children = ( @@ -67,7 +56,6 @@ BF43429C1B416FDD002FDE1F /* ExpandableLabelDemoSPM */ = { isa = PBXGroup; children = ( - BF0468101B44121F009EC2F9 /* Classes */, BF43429F1B416FDD002FDE1F /* AppDelegate.swift */, BF4342A11B416FDD002FDE1F /* ViewController.swift */, BF38D1C71B42EE3E000091FD /* ExpandableCell.swift */, @@ -161,7 +149,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - BF0468121B44121F009EC2F9 /* ExpandableLabel.swift in Sources */, BF4342A21B416FDD002FDE1F /* ViewController.swift in Sources */, BF4342A01B416FDD002FDE1F /* AppDelegate.swift in Sources */, BF38D1C81B42EE3E000091FD /* ExpandableCell.swift in Sources */, From d8bc7f26da317e2bfec3dc5017b0ef5925e6119c Mon Sep 17 00:00:00 2001 From: Enrique Garcia Date: Tue, 30 Mar 2021 19:50:37 +0200 Subject: [PATCH 6/8] use ExpandableLabel framework from SPM on ExpandableLabelDemoSPM project --- .../project.pbxproj | 43 ++++++++++++++++--- .../Base.lproj/Main.storyboard | 6 +-- .../ExpandableCell.swift | 1 + .../ViewController.swift | 1 + 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj index 64e1ba2..4d3e089 100644 --- a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ @@ -13,6 +13,7 @@ BF4342A51B416FDD002FDE1F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF4342A31B416FDD002FDE1F /* Main.storyboard */; }; BF4342A71B416FDD002FDE1F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BF4342A61B416FDD002FDE1F /* Images.xcassets */; }; BF4342AA1B416FDD002FDE1F /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = BF4342A81B416FDD002FDE1F /* LaunchScreen.xib */; }; + C04E06BB261396CA00296E2E /* ExpandableLabel in Frameworks */ = {isa = PBXBuildFile; productRef = C04E06BA261396CA00296E2E /* ExpandableLabel */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -24,6 +25,7 @@ BF4342A41B416FDD002FDE1F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; BF4342A61B416FDD002FDE1F /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; BF4342A91B416FDD002FDE1F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; + C04E06B8261396A500296E2E /* ExpandableLabel */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ExpandableLabel; path = ..; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -31,6 +33,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + C04E06BB261396CA00296E2E /* ExpandableLabel in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -40,8 +43,10 @@ BF4342911B416FDD002FDE1F = { isa = PBXGroup; children = ( + C04E06B8261396A500296E2E /* ExpandableLabel */, BF43429C1B416FDD002FDE1F /* ExpandableLabelDemoSPM */, BF43429B1B416FDD002FDE1F /* Products */, + C04E06B9261396CA00296E2E /* Frameworks */, ); sourceTree = ""; }; @@ -75,6 +80,13 @@ name = "Supporting Files"; sourceTree = ""; }; + C04E06B9261396CA00296E2E /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -91,6 +103,9 @@ dependencies = ( ); name = ExpandableLabelDemoSPM; + packageProductDependencies = ( + C04E06BA261396CA00296E2E /* ExpandableLabel */, + ); productName = ExpandableLabelDemo; productReference = BF43429A1B416FDD002FDE1F /* ExpandableLabelDemoSPM.app */; productType = "com.apple.product-type.application"; @@ -108,7 +123,7 @@ TargetAttributes = { BF4342991B416FDD002FDE1F = { CreatedOnToolsVersion = 6.3.2; - LastSwiftMigration = 0900; + LastSwiftMigration = 1240; }; }; }; @@ -275,7 +290,8 @@ IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -285,10 +301,13 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = ExpandableLabelDemoSPM/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = "de.apploft.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -297,10 +316,13 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = ExpandableLabelDemoSPM/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = "de.apploft.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -326,6 +348,13 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + C04E06BA261396CA00296E2E /* ExpandableLabel */ = { + isa = XCSwiftPackageProductDependency; + productName = ExpandableLabel; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = BF4342921B416FDD002FDE1F /* Project object */; } diff --git a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/Main.storyboard b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/Main.storyboard index e73040c..439627a 100644 --- a/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/Main.storyboard +++ b/ExpandableLabelDemoSPM/ExpandableLabelDemoSPM/Base.lproj/Main.storyboard @@ -12,20 +12,20 @@ - + - + -