Skip to content

Commit

Permalink
Merge pull request #428 from BookerSoftwareInc/SPM-compatibility
Browse files Browse the repository at this point in the history
Fix Swift PM compatibility by creating a separate ObjC target
  • Loading branch information
suzuki-0000 authored Jul 29, 2022
2 parents 42a10eb + 13edefc commit 6577850
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 15 deletions.
20 changes: 18 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.0
// swift-tools-version:5.3
//
// Package.swift
//
Expand All @@ -18,6 +18,22 @@ let package = Package(
targets: [
.target(
name: "SKPhotoBrowser",
path: "SKPhotoBrowser")
dependencies: ["SKPhotoBrowserObjC"],
path: "SKPhotoBrowser",
exclude: ["Info.plist",
"extensions/ObjC"],
resources: [
.copy("SKPhotoBrowser.bundle")
]),
.target(
name: "SKPhotoBrowserObjC",
path: "SKPhotoBrowser/extensions/ObjC",
publicHeadersPath: "."),
.testTarget(
name: "SKPhotoBrowserTests",
dependencies: ["SKPhotoBrowser"],
path: "SKPhotoBrowserTests",
exclude: ["Info.plist"]
)
]
)
16 changes: 14 additions & 2 deletions SKPhotoBrowser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
9521CC65232F677A00446D11 /* UIView+Radius.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9521CC62232F677900446D11 /* UIView+Radius.swift */; };
9521CC6B232F693800446D11 /* UIImage+animatedGIF.h in Headers */ = {isa = PBXBuildFile; fileRef = 9521CC69232F693800446D11 /* UIImage+animatedGIF.h */; settings = {ATTRIBUTES = (Public, ); }; };
9521CC6C232F693800446D11 /* UIImage+animatedGIF.m in Sources */ = {isa = PBXBuildFile; fileRef = 9521CC6A232F693800446D11 /* UIImage+animatedGIF.m */; };
9CF727E1285208180043487A /* UIImage+BundledImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CF727E0285208180043487A /* UIImage+BundledImage.swift */; };
A64B89361CB04222000071B9 /* SKPhotoBrowserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A64B89351CB04222000071B9 /* SKPhotoBrowserTests.swift */; };
A64B89381CB04222000071B9 /* SKPhotoBrowser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8909B5301BC791280060A053 /* SKPhotoBrowser.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -78,6 +79,7 @@
9521CC62232F677900446D11 /* UIView+Radius.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Radius.swift"; sourceTree = "<group>"; };
9521CC69232F693800446D11 /* UIImage+animatedGIF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+animatedGIF.h"; sourceTree = "<group>"; };
9521CC6A232F693800446D11 /* UIImage+animatedGIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+animatedGIF.m"; sourceTree = "<group>"; };
9CF727E0285208180043487A /* UIImage+BundledImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+BundledImage.swift"; sourceTree = "<group>"; };
A64B89331CB04222000071B9 /* SKPhotoBrowserTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SKPhotoBrowserTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A64B89351CB04222000071B9 /* SKPhotoBrowserTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SKPhotoBrowserTests.swift; sourceTree = "<group>"; };
A64B89371CB04222000071B9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -153,15 +155,24 @@
9521CC5F232F677900446D11 /* extensions */ = {
isa = PBXGroup;
children = (
9521CC69232F693800446D11 /* UIImage+animatedGIF.h */,
9521CC6A232F693800446D11 /* UIImage+animatedGIF.m */,
9CF727DF285208020043487A /* ObjC */,
9521CC60232F677900446D11 /* UIApplication+UIWindow.swift */,
9CF727E0285208180043487A /* UIImage+BundledImage.swift */,
9521CC61232F677900446D11 /* UIImage+Rotation.swift */,
9521CC62232F677900446D11 /* UIView+Radius.swift */,
);
path = extensions;
sourceTree = "<group>";
};
9CF727DF285208020043487A /* ObjC */ = {
isa = PBXGroup;
children = (
9521CC69232F693800446D11 /* UIImage+animatedGIF.h */,
9521CC6A232F693800446D11 /* UIImage+animatedGIF.m */,
);
path = ObjC;
sourceTree = "<group>";
};
A64B89341CB04222000071B9 /* SKPhotoBrowserTests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -321,6 +332,7 @@
8909B5461BC791510060A053 /* SKIndicatorView.swift in Sources */,
8917B1B41D5A14B0000CE1C4 /* SKButtons.swift in Sources */,
89C24A821D657AD1005F09A9 /* SKPhotoBrowserOptions.swift in Sources */,
9CF727E1285208180043487A /* UIImage+BundledImage.swift in Sources */,
26C97AD51D0EB6870039F6CB /* SKCache.swift in Sources */,
8909B5431BC791510060A053 /* SKCaptionView.swift in Sources */,
8909B5491BC791510060A053 /* SKPhotoBrowser.swift in Sources */,
Expand Down
6 changes: 1 addition & 5 deletions SKPhotoBrowser/SKButtons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

import UIKit

// helpers which often used
private let bundle = Bundle(for: SKPhotoBrowser.self)

class SKButton: UIButton {
internal var showFrame: CGRect!
internal var hideFrame: CGRect!
Expand All @@ -33,8 +30,7 @@ class SKButton: UIButton {
translatesAutoresizingMaskIntoConstraints = true
autoresizingMask = [.flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin]

let image = UIImage(named: "SKPhotoBrowser.bundle/images/\(imageName)", in: bundle, compatibleWith: nil) ?? UIImage()
setImage(image, for: .normal)
setImage(UIImage.bundledImage(named: imageName), for: .normal)
}

func setFrameSize(_ size: CGSize? = nil) {
Expand Down
8 changes: 2 additions & 6 deletions SKPhotoBrowser/SKPaginationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import UIKit

private let bundle = Bundle(for: SKPhotoBrowser.self)

class SKPaginationView: UIView {
var counterLabel: UILabel?
var prevButton: UIButton?
Expand Down Expand Up @@ -142,10 +140,8 @@ class SKPaginationButton: UIButton {
.flexibleRightMargin,
.flexibleTopMargin]
contentMode = .center

let image = UIImage(named: "SKPhotoBrowser.bundle/images/\(imageName)",
in: bundle, compatibleWith: nil) ?? UIImage()
setImage(image, for: .normal)

setImage(UIImage.bundledImage(named: imageName), for: .normal)
}
}

Expand Down
3 changes: 3 additions & 0 deletions SKPhotoBrowser/SKPhoto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import UIKit
#if canImport(SKPhotoBrowserObjC)
import SKPhotoBrowserObjC
#endif

@objc public protocol SKPhotoProtocol: NSObjectProtocol {
var index: Int { get set }
Expand Down
3 changes: 3 additions & 0 deletions SKPhotoBrowser/SKPhotoBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//

#import <UIKit/UIKit.h>

#if __has_include("UIImage+animatedGIF.h")
#import "UIImage+animatedGIF.h"
#endif

//! Project version number for SKPhotoBrowser.
FOUNDATION_EXPORT double SKPhotoBrowserVersionNumber;
Expand Down
20 changes: 20 additions & 0 deletions SKPhotoBrowser/extensions/UIImage+BundledImage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// UIImage+BundledImage.swift
//
//
// Created by Aleksandr Solovev on 09.06.2022.
//

import UIKit

extension UIImage {
static func bundledImage(named imageName: String) -> UIImage {
let imagePath = "SKPhotoBrowser.bundle/images/\(imageName)"
#if SWIFT_PACKAGE
return UIImage(named: imagePath, in: .module, compatibleWith: nil) ?? UIImage()
#else
let bundle = Bundle(for: SKPhotoBrowser.self)
return UIImage(named: imagePath, in: bundle, compatibleWith: nil) ?? UIImage()
#endif
}
}

0 comments on commit 6577850

Please sign in to comment.