SwifterSwift v5.2.0 Release Notes

Release Date: 2020-04-05 // 6 months ago
  • โž• Added

    • CATransform3D:
      • identity, isIdentity, init(translationX:y:z:), init(scaleX:y:z:), init(rotationAngle:x:y:z:), translatedBy(x:y:z:), scaledBy(x:y:z:), rotated(by:x:y:z:), inverted(), concatenating(_:), translateBy(x:y:z:), scaleBy(x:y:z:), rotate(by:x:y:z:), invert(), concatenate(_:), isAffine and affineTransform(). Also conforms to Codable and Equatable. #819 by guykogus
    • CGAffineTransform:
    • NotificationCenter:
      • observeOnce(forName:object:queue:using:) for observing a single posting of a notification. #812 by guykogus
    • Optional:
      • Conform to Equatable when Wrapped is RawRepresentable and its RawValue is Equatable. #804 by guykogus
    • CoreLocation:
      • Added Array where Element: CLLocation extension and added distance(unitLength:) function. #799 by trevorphillips
    • Decodable:
      • Added init?(data:decoder:) to decode Decodable (Codable) type models. #797 by Mustafa GUNES.
    • CLVisit:
    • EdgeInsets:
      • Unified UIEdgeInsets and NSEdgeInsets into a single typealias, EdgeInsets, similar to what we do with UIColor and NSColor. For the tests to function it was required to add the static zero property to NSEdgeInsets and to make it conform to Equatable. #785 by guykogus
    • Array:
      • Added sorted(like:keyPath:) to sort an array like another array based on a key path. #772 by MaxHaertwig.
    • MKMapView:
      • Added zoom(to:meter:edgePadding:animated:) method to zoom multiple MKMapView coordinates. #723 by Mustafa GUNES.
    • Dictionary:
      • Added init(grouping:by:) to initialize a dictionary by grouping sequence from a hashable KeyPath. #751 by mmdock
    • RangeReplaceableCollection:
      • Added removeDuplicates(keyPath:) for removing duplicate elements based on key path. #737 by Ilya Glushchuk.
    • Color:
      • Added init(light:dark:) to create an NSColor/UIColor with different variations for light and dark mode. Only available in iOS/tvOS 13.0, macOS 10.15. #722 by MaxHaertwig.
    • String:
      • Added withPrefix(_:), which provides a method to add a prefix to a string. If the string already has that prefix, it simply returns the original string. #720 by Zach Frew.
    • NSRegularExpression:
      • Added enumerateMatches(in:options:range:using:), matches(in:options:range:), numberOfMatches(in:options:range:), firstMatch(in:options:range:), rangeOfFirstMatch(in:options:range:), stringByReplacingMatches(in:options:range:withTemplate:), replaceMatches(in:options:range:withTemplate:), which use String and String.Range in place of NSString and NSRange to make the calls Swifter. #727 by guykogus.
    • UIBarButtonItem:
      • Added flexibleSpace and fixedSpace(width:) extensions to UIBarButtonItem to simplify the creation of spacers. #728 by MaxHaertwig.
    • UIImage:
      • Added missing test for compressedData(quality:). #786 by thisIsTheFoxe
      • Added withBackgroundColor(_:) to specify a background color for a partially transparent image. #721 by MaxHaertwig.
      • Added init?(base64String:) to create a UIImage from a base-64 String. #741 by @thisIsTheFoxe
      • Added pngBase64String(), jpegBase64String(compressionQuality:) which return a Base 64 String representation of the UIImages PNG or JPEG data. #747 by Moritz Sternemann.
      • Added init?(url:scale:) to initialize a UIImage with a given url and scale factor. #753 by mmdock
    • CAGradientLayer:
      • Added init(colors:locations:startPoint:endPoint:type:) convenience initializer. #726 by JayMehta97.
    • Sequence:
      • Added sum(for:) to sum up an AdditiveArithmetic property, referenced by KeyPath, of all elements in a sequence. #736 by Moritz Sternemann.
      • Added sorted(by:and:) and sorted(by:and:and:) to obtain a sorted sequence based on multiple key paths. #796 by MaxHaertwig.
      • Added map(by:) to map the sequence elements by a given key path. #763 by Roman Podymov.
      • Added compactMap(by:) to map the sequence elements by a given key path to the non-nil elements array. #766 by Roman Podymov.
      • Added filter(by:) to filter the sequence elements by a given boolean key path. #771 by Roman Podymov.
    • MutableCollection:
      • Added assignToAll(value:keyPath:) to assign given value to field keyPath of every element in the collection. #759 by cyber-gh.
      • Added sort(by:and:) and sort(by:and:and:) to sort a sequence based on multiple key paths. #796 by MaxHaertwig.
    • KeyedDecodingContainer:
      • Added decodeBoolAsIntOrString(key:) to try to decode a Bool as Int then String before decoding as Bool. #750 by FraDeliro.
      • Added decodeBoolAsIntOrStringIfPresent(key:) to try to decode a Bool as Int then String before decoding as Bool if present. #750 by FraDeliro.
    • Locale:
      • Added is12HourTimeFormat to indicate if locale has 12h format. #793 by DimaZava.
      • flagEmoji(forRegionCode:) to convert a region code into the corresponding flag emoji. #813 by guykogus
    • URLRequest:
      • init(string:relativeTo:) to allow initializing a URL with an optional String. #818 by guykogus
      • Added curlString property to get a cURL command representation of this URL request. #790 by DimaZava.
    • SKProduct:
    • CGRect
      • Added property center. #814 by qchenqizhi.
      • Added initializer init(center:size:) to create CGRect with center and size. #814 by qchenqizhi.
      • Added resizing(to:anchor:) to create CGRect by resizing with anchor. #814 by qchenqizhi.

    ๐Ÿ”„ Changed

    • Collection:
      • Refactored group(by:) to be generic for all Collections, not only where Index == Int. #758 by guykogus
    • UIImage:
      • Implemented filled(withColor:) using UIGraphicsImageRenderer when available. #733
      • Updated kilobytesSize to be computed independently from bytesSize #753 by mmdock
      • Updated init?(base64String:) to take in a scale factor paramater. #753 by mmdock
    • UIImage:
      • Refactored tint(_:blendMode:) using UIGraphicsImageRenderer if available. #731 by FraDeliro.
    • Sequence:
      • Corrected documentation for sorted(by:with:) and sorted(by:). #751 by mmdock
    • NSAttributedString:
      • Update applying(attributes: [NSAttributedString.Key : Any], toRangesMatching pattern: String) to respond applying(attributes: [NSAttributedString.Key : Any], toRangesMatching pattern: String, options: NSRegularExpression.Options = []) signature to support regular expression options. #791 by DimaZava
    • UIButton:
      • Refactored centerTextAndImage(spacing:): now the image position can be above the text, by setting a new parameter imageAboveText to true. #807 by qchenqizhi.
    • String:
      • Bug fix String[safe:], subscript should not crash. #816 by cHaLkdusT

    ๐Ÿ›  Fixed

    • ๐Ÿ›  Fixed build error occurring when building AppKit extensions for macCatalyst. #762 by MaxHaertwig.
    • ๐Ÿ›  Fixed String.base64Decoded making it a safe decode by including padding on the string. #801 by LucianoPAlmeida.
    • ๐Ÿ›  Fixed UIImage.cropped(to:) making it work correctly with scaled image. #811 by qchenqizhi.


Previous changes from v5.1.0

  • โž• Added

    • Array:

      • Added withoutDuplicates(keyPath:) for filtering duplicate elements based on key path. #704 by RomanPodymov.
    • Sequence:

      • Added withoutDuplicates(transform:) for remove duplicate elements based on condition in a sequence. #666 by saucym
      • Added sorted(by:with:) to return sorted array from a Sequence with by a given keyPath using a compare function. #712 by LucianoPAlmeida
    • MutableCollection:

      • Added sort(by:with:) to sort a Collection with by a given keyPath using a compare function. #712 by LucianoPAlmeida
    • String

      • isPalindrome computed property of String to check if it is a palindrome. #671 by cHaLkdusT.
    • CGSize:

      • Added aspectRatio, maxDimension, and minDimension properties. #662 by MaxHaertwig.
    • SCNBox:

      • Added init(width:height:length:), init(sideLength:chamferRadius:), init(width:height:length:chamferRadius:material:), init(sideLength:chamferRadius:material:), init(width:height:length:chamferRadius:color:), and init(sideLength:chamferRadius:color:) convenience initializers. #660 by MaxHaertwig.
    • SCNCapsule:

      • Added init(capDiameter:height), init(capRadius:height:material:), init(capDiameter:height:material:), init(capRadius:height:color:), and init(capDiameter:height:color:) convenience initializers. #660 by MaxHaertwig.
    • SCNCone:

      • Added init(topDiameter:bottomDiameter:height), init(topRadius:bottomRadius:height:material:), init(topDiameter:bottomDiameter:height:material:), init(topRadius:bottomRadius:height:color:), and init(topDiameter:bottomDiameter:height:color:) convenience initializers. #660 by MaxHaertwig.
    • SCNCylinder:

      • Added init(diameter:height), init(radius:height:material:), init(diameter:height:material:), init(radius:height:color:), and init(diameter:height:color:) convenience initializers. #660 by MaxHaertwig
    • SCNGeometry:

      • Added boundingSize property to get the size of the geometry's bounding box. #660 by MaxHaertwig.
    • SCNMaterial:

    • SCNPlane:

      • Added init(width:), init(width:height:material:), init(width:material:), init(width:height:color:), and init(width:color:) convenience initializers. #660 by MaxHaertwig.
    • SCNShape:

      • Added init(path:extrusionDepth:material:) and init(path:extrusionDepth:color:) convenience initializers. #660 by MaxHaertwig.
    • SCNSphere:

      • Added init(diameter:), init(radius:material:), init(radius:color:), init(diameter:material:), and init(diameter:color:) convenience initializers. #660 by MaxHaertwig.
    • SCNVector3:

      • Added absolute property to calculate the vector's components as absolute values. #660 by MaxHaertwig.
      • Added length property to calculate the vector's length. #660 by MaxHaertwig.
    • UICollectionView:

      • Added isValidIndexPath(_:) method to check whether given IndexPath is valid within UICollectionView. #695 by emilrb.
      • Added safeScrollToItem(at:at:animated:) method to safely scroll UICollectionView to the given IndexPath. #698 by emilrb
    • Sequence:

      • Moved divided(by:) ArrayExtensions to SequenceExtensions. This function separates all items into 2 lists based on a given predicate. #706 by cHaLkdusT
    • UIBezierPath:

      • Added init(from:to:), init(points:), init(polygonWithPoints:), init(ovalOf:centered:) and init(rectOf:centered:) convenience initializers. #659 by MaxHaertwig.

    ๐Ÿ”„ Changed

    • UIApplication:

    • Sequence:

    ๐Ÿ—„ Deprecated

    • Array:
      • Deprecated sorted(by:, ascending) and sort(by:ascending) in favor of sorted(by:with:) and sort(by:with:) #712 by LucianoPAlmeida

    โœ‚ Removed

    • Character:

      • Removed isNumber, isLetter, isLowercased, isUppercased and isWhiteSpace because the same properties are defined in the Swift standard library. #689 by RomanPodymov.
    • Array:

      • Removed divided(by:) function from ArrayExtensions #706 by cHaLkdusT

    ๐Ÿ›  Fixed

    • UIApplication:

      • Resolved an issue where version would return the wrong Info.plist value.
      • Resolved an issue where version and displayName would return nil if localized.
    • UIImage:

      • The size of rect can equal to the size of UIImage when using cropped(to:) to crop UIImage. #679 by dirtmelon.
      • scaled(toHeight:opaque:) and scaled(toWidth:opaque:) will now keep the original scale of UIImage. #703 by ShannonChou
    • UITableView:

      • isValidIndexPath(_:) will now return false for IndexPaths with a negative row or section. #696 by emilrb.