Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Objective C #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Example/SwiftWebVCExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
00FFF85E1E09977500015C59 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 00FFF85C1E09977500015C59 /* Main.storyboard */; };
00FFF8601E09977500015C59 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 00FFF85F1E09977500015C59 /* Assets.xcassets */; };
00FFF8631E09977500015C59 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 00FFF8611E09977500015C59 /* LaunchScreen.storyboard */; };
C7F2B30A2044309100DB7E6D /* ObjcViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C7F2B3092044309100DB7E6D /* ObjcViewController.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -46,6 +47,9 @@
00FFF85F1E09977500015C59 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
00FFF8621E09977500015C59 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
00FFF8641E09977500015C59 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C7F2B3072044309100DB7E6D /* SwiftWebVCExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SwiftWebVCExample-Bridging-Header.h"; sourceTree = "<group>"; };
C7F2B3082044309100DB7E6D /* ObjcViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ObjcViewController.h; sourceTree = "<group>"; };
C7F2B3092044309100DB7E6D /* ObjcViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ObjcViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -116,10 +120,21 @@
00FFF85F1E09977500015C59 /* Assets.xcassets */,
00FFF8611E09977500015C59 /* LaunchScreen.storyboard */,
00FFF8641E09977500015C59 /* Info.plist */,
C7F2B30C20444D3200DB7E6D /* Objective C VC */,
);
path = SwiftWebVCExample;
sourceTree = "<group>";
};
C7F2B30C20444D3200DB7E6D /* Objective C VC */ = {
isa = PBXGroup;
children = (
C7F2B3082044309100DB7E6D /* ObjcViewController.h */,
C7F2B3092044309100DB7E6D /* ObjcViewController.m */,
C7F2B3072044309100DB7E6D /* SwiftWebVCExample-Bridging-Header.h */,
);
name = "Objective C VC";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -209,6 +224,7 @@
0055F7A81E259F1A000ECD54 /* SwiftModalWebVC.swift in Sources */,
00FFF85B1E09977500015C59 /* ViewController.swift in Sources */,
0055F7AC1E259F1A000ECD54 /* SwiftWebVCActivitySafari.swift in Sources */,
C7F2B30A2044309100DB7E6D /* ObjcViewController.m in Sources */,
00FFF8591E09977500015C59 /* AppDelegate.swift in Sources */,
0055F7A91E259F1A000ECD54 /* SwiftWebVC.swift in Sources */,
0055F7AA1E259F1A000ECD54 /* SwiftWebVCActivity.swift in Sources */,
Expand Down Expand Up @@ -366,11 +382,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = SwiftWebVCExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.swiftweb.SwiftWebVCExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SwiftWebVCExample/SwiftWebVCExample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
};
name = Debug;
Expand All @@ -379,11 +398,13 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = SwiftWebVCExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.swiftweb.SwiftWebVCExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SwiftWebVCExample/SwiftWebVCExample-Bridging-Header.h";
SWIFT_VERSION = 4.0;
};
name = Release;
Expand Down
62 changes: 57 additions & 5 deletions Example/SwiftWebVCExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="zaI-sO-1Yv">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="zaI-sO-1Yv">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -38,7 +38,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="QSh-Xk-40Y">
<rect key="frame" x="34" y="319.5" width="307" height="28"/>
<rect key="frame" x="33.5" y="319.5" width="308" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Open Google.com With Default Theme (Light Blue)"/>
<connections>
Expand All @@ -52,13 +52,21 @@
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8ec-UK-JwU">
<rect key="frame" x="112" y="233.5" width="152" height="28"/>
<rect key="frame" x="111.5" y="233.5" width="153" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Open Google.com (Push)"/>
<connections>
<action selector="push" destination="bLx-fa-uWl" eventType="touchUpInside" id="7ei-rv-Ow1"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gnX-vb-suy">
<rect key="frame" x="106.5" y="451.5" width="163" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Open ObjC View Controller"/>
<connections>
<segue destination="iZI-zi-fYs" kind="show" id="gvz-mW-MKZ"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand All @@ -67,10 +75,12 @@
<constraint firstItem="QSh-Xk-40Y" firstAttribute="centerY" secondItem="bXY-Xx-qq8" secondAttribute="centerY" id="AKe-Ro-lFE"/>
<constraint firstItem="QSh-Xk-40Y" firstAttribute="centerX" secondItem="bXY-Xx-qq8" secondAttribute="centerX" id="MkB-QK-YWL"/>
<constraint firstItem="8ec-UK-JwU" firstAttribute="centerX" secondItem="bXY-Xx-qq8" secondAttribute="centerX" id="Nru-Ws-bMg"/>
<constraint firstItem="gnX-vb-suy" firstAttribute="top" secondItem="k3S-Y4-F4d" secondAttribute="bottom" constant="8" symbolic="YES" id="R64-69-a0Z"/>
<constraint firstItem="081-aS-c8D" firstAttribute="top" secondItem="8ec-UK-JwU" secondAttribute="bottom" constant="34" id="a5j-rN-XVI"/>
<constraint firstItem="QSh-Xk-40Y" firstAttribute="top" secondItem="081-aS-c8D" secondAttribute="bottom" constant="8" id="cJl-nW-KQw"/>
<constraint firstItem="k3S-Y4-F4d" firstAttribute="top" secondItem="E22-Wf-Eov" secondAttribute="bottom" constant="20" id="gz9-W9-QQR"/>
<constraint firstItem="081-aS-c8D" firstAttribute="centerX" secondItem="bXY-Xx-qq8" secondAttribute="centerX" id="k5b-et-2SC"/>
<constraint firstItem="gnX-vb-suy" firstAttribute="centerX" secondItem="bXY-Xx-qq8" secondAttribute="centerX" id="pO5-x9-qpM"/>
<constraint firstItem="E22-Wf-Eov" firstAttribute="centerX" secondItem="bXY-Xx-qq8" secondAttribute="centerX" id="v86-bT-iv3"/>
</constraints>
</view>
Expand All @@ -80,13 +90,55 @@
</objects>
<point key="canvasLocation" x="972" y="38.23088455772114"/>
</scene>
<!--Objective C View Controller-->
<scene sceneID="XbY-Hc-R7a">
<objects>
<viewController title="Objective C View Controller" id="iZI-zi-fYs" customClass="ObjcViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="DUs-zs-qtm"/>
<viewControllerLayoutGuide type="bottom" id="IjV-JN-azg"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="xuX-S4-rsJ">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9Ql-mx-b7O">
<rect key="frame" x="78.5" y="319" width="218" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Open Modal SwiftWebVC from ObjC"/>
<connections>
<action selector="modalButtonPressed:" destination="iZI-zi-fYs" eventType="touchUpInside" id="9Wu-Cs-d02"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ESP-Fd-DL2">
<rect key="frame" x="100.5" y="271" width="174" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Push SwiftWebVC from ObjC"/>
<connections>
<action selector="pushButtonPressed:" destination="iZI-zi-fYs" eventType="touchUpInside" id="I14-sy-qKu"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="ESP-Fd-DL2" firstAttribute="centerX" secondItem="xuX-S4-rsJ" secondAttribute="centerX" id="ZuU-7Q-bTz"/>
<constraint firstItem="9Ql-mx-b7O" firstAttribute="centerY" secondItem="xuX-S4-rsJ" secondAttribute="centerY" id="b12-fR-naw"/>
<constraint firstItem="9Ql-mx-b7O" firstAttribute="top" secondItem="ESP-Fd-DL2" secondAttribute="bottom" constant="20" id="dMa-9S-R86"/>
<constraint firstItem="9Ql-mx-b7O" firstAttribute="centerX" secondItem="xuX-S4-rsJ" secondAttribute="centerX" id="jln-85-pMp"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="gW9-Tx-ArU" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1698" y="38"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="QX7-vu-2kr">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="zaI-sO-1Yv" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="heT-aK-khc">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand Down
13 changes: 13 additions & 0 deletions Example/SwiftWebVCExample/ObjcViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ObjcViewController.h
// SwiftWebVCExample
//
// Created by L4grange on 26/02/2018.
// Copyright © 2018 Myles Ringle. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ObjcViewController : UIViewController

@end
47 changes: 47 additions & 0 deletions Example/SwiftWebVCExample/ObjcViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// ObjcViewController.m
// SwiftWebVCExample
//
// Created by L4grange on 26/02/2018.
// Copyright © 2018 Myles Ringle. All rights reserved.
//

#import "ObjcViewController.h"
#import "SwiftWebVCExample-Swift.h"

@interface ObjcViewController () <SwiftWebVCDelegate>

@end

@implementation ObjcViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)pushButtonPressed:(UIButton *)sender {
SwiftWebVC *webVC = [[SwiftWebVC alloc] initWithUrlString:@"https://www.google.com" sharingEnabled:YES];
webVC.delegate = self;
[self.navigationController pushViewController:webVC animated:YES];
}

- (IBAction)modalButtonPressed:(UIButton *)sender {
SwiftModalWebVC *webVC = [[SwiftModalWebVC alloc] initWithUrlString:@"https://www.google.com" sharingEnabled:YES];
[self presentViewController:webVC animated:YES completion:nil];
}

-(void)didStartLoading {
NSLog(@"ObjC: Started loading.");
}

-(void)didFinishLoadingWithSuccess:(BOOL)success {
NSLog(@"ObjC: Finished loading. Success: %@.", success ? @"YES" : @"NO" );
}

@end
4 changes: 4 additions & 0 deletions Example/SwiftWebVCExample/SwiftWebVCExample-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

16 changes: 8 additions & 8 deletions SwiftWebVC/SwiftModalWebVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ import UIKit

public class SwiftModalWebVC: UINavigationController {

public enum SwiftModalWebVCTheme {
@objc public enum SwiftModalWebVCTheme: Int {
case lightBlue, lightBlack, dark
}
public enum SwiftModalWebVCDismissButtonStyle {
@objc public enum SwiftModalWebVCDismissButtonStyle: Int {
case arrow, cross
}

weak var webViewDelegate: UIWebViewDelegate? = nil
@objc weak var webViewDelegate: UIWebViewDelegate? = nil

public convenience init(urlString: String, sharingEnabled: Bool = true) {
@objc public convenience init(urlString: String, sharingEnabled: Bool = true) {
var urlString = urlString
if !urlString.hasPrefix("https://") && !urlString.hasPrefix("http://") {
urlString = "https://"+urlString
}
self.init(pageURL: URL(string: urlString)!, sharingEnabled: sharingEnabled)
}

public convenience init(urlString: String, theme: SwiftModalWebVCTheme, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle, sharingEnabled: Bool = true) {
@objc public convenience init(urlString: String, theme: SwiftModalWebVCTheme, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle, sharingEnabled: Bool = true) {
self.init(pageURL: URL(string: urlString)!, theme: theme, dismissButtonStyle: dismissButtonStyle, sharingEnabled: sharingEnabled)
}

public convenience init(pageURL: URL, sharingEnabled: Bool = true) {
@objc public convenience init(pageURL: URL, sharingEnabled: Bool = true) {
self.init(request: URLRequest(url: pageURL), sharingEnabled: sharingEnabled)
}

public convenience init(pageURL: URL, theme: SwiftModalWebVCTheme, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle, sharingEnabled: Bool = true) {
@objc public convenience init(pageURL: URL, theme: SwiftModalWebVCTheme, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle, sharingEnabled: Bool = true) {
self.init(request: URLRequest(url: pageURL), theme: theme, dismissButtonStyle: dismissButtonStyle, sharingEnabled: sharingEnabled)
}

public init(request: URLRequest, theme: SwiftModalWebVCTheme = .lightBlue, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle = .arrow, sharingEnabled: Bool = true) {
@objc public init(request: URLRequest, theme: SwiftModalWebVCTheme = .lightBlue, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle = .arrow, sharingEnabled: Bool = true) {
let webViewController = SwiftWebVC(aRequest: request)
webViewController.sharingEnabled = sharingEnabled
webViewController.storedStatusColor = UINavigationBar.appearance().barStyle
Expand Down
Loading