Skip to content

Commit 7e23eb5

Browse files
committed
[Swift iOS Example] Add example project for using peertalk in a Swift app
`PTChannel` 1. Overloads exposing fewer parameters are now `NS_SWIFT_UNAVAILABLE`. Instead we have a single method that defines the nullability of arguments. 2. Used `NS_ASSUME_NONNULL_BEGIN` and `NS_ASSUME_NONNULL_END` 3. Renamed some methods so argument labels are exposed to swift properly. E.g. `init(with:delegate:)` becomes `init(protocol:delegate:)` 4. Added `_Nullable` where necessary to block callback arguments. `Peertalk iOS Example Swift` This duplicates the ObjC Swift iOS Example. It uses the same wire format as the ObjC examples, so they can talk to each other. If 2 swift apps were talking together then it would be trivial to pass payloads of and Codeable structs (encoded any way you like: JSON, Plist, MessagePack, etc)
1 parent 4b5ec18 commit 7e23eb5

37 files changed

+1115
-468
lines changed

Peertalk Example/Peertalk Example-Prefix.pch

-7
This file was deleted.

Peertalk Example/en.lproj/Credits.rtf

-29
This file was deleted.

Peertalk Example/en.lproj/InfoPlist.strings

-2
This file was deleted.
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// AppDelegate.swift
3+
// Peertalk Swift
4+
//
5+
// Created by Jonathan Dann on 04/12/2020.
6+
//
7+
8+
import UIKit
9+
10+
@main
11+
class AppDelegate: UIResponder, UIApplicationDelegate {
12+
13+
14+
15+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
16+
// Override point for customization after application launch.
17+
return true
18+
}
19+
20+
// MARK: UISceneSession Lifecycle
21+
22+
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
23+
// Called when a new scene session is being created.
24+
// Use this method to select a configuration to create the new scene with.
25+
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
26+
}
27+
28+
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
29+
// Called when the user discards a scene session.
30+
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
31+
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
32+
}
33+
34+
35+
}
36+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"scale" : "2x",
6+
"size" : "20x20"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"scale" : "3x",
11+
"size" : "20x20"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"scale" : "2x",
16+
"size" : "29x29"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"scale" : "3x",
21+
"size" : "29x29"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"scale" : "2x",
26+
"size" : "40x40"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"scale" : "3x",
31+
"size" : "40x40"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"scale" : "2x",
36+
"size" : "60x60"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"scale" : "3x",
41+
"size" : "60x60"
42+
},
43+
{
44+
"idiom" : "ipad",
45+
"scale" : "1x",
46+
"size" : "20x20"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"scale" : "2x",
51+
"size" : "20x20"
52+
},
53+
{
54+
"idiom" : "ipad",
55+
"scale" : "1x",
56+
"size" : "29x29"
57+
},
58+
{
59+
"idiom" : "ipad",
60+
"scale" : "2x",
61+
"size" : "29x29"
62+
},
63+
{
64+
"idiom" : "ipad",
65+
"scale" : "1x",
66+
"size" : "40x40"
67+
},
68+
{
69+
"idiom" : "ipad",
70+
"scale" : "2x",
71+
"size" : "40x40"
72+
},
73+
{
74+
"idiom" : "ipad",
75+
"scale" : "1x",
76+
"size" : "76x76"
77+
},
78+
{
79+
"idiom" : "ipad",
80+
"scale" : "2x",
81+
"size" : "76x76"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"scale" : "2x",
86+
"size" : "83.5x83.5"
87+
},
88+
{
89+
"idiom" : "ios-marketing",
90+
"scale" : "1x",
91+
"size" : "1024x1024"
92+
}
93+
],
94+
"info" : {
95+
"author" : "xcode",
96+
"version" : 1
97+
}
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
5+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<scenes>
9+
<!--View Controller-->
10+
<scene sceneID="EHf-IW-A2E">
11+
<objects>
12+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
13+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
14+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
15+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
16+
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
17+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
18+
</view>
19+
</viewController>
20+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
21+
</objects>
22+
<point key="canvasLocation" x="53" y="375"/>
23+
</scene>
24+
</scenes>
25+
</document>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17700" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<device id="retina5_5" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
6+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
7+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
8+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9+
</dependencies>
10+
<scenes>
11+
<!--View Controller-->
12+
<scene sceneID="tne-QT-ifu">
13+
<objects>
14+
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Peertalk_Swift" customModuleProvider="target" sceneMemberID="viewController">
15+
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
16+
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
17+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18+
<subviews>
19+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="7On-uZ-aZ1">
20+
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
21+
<subviews>
22+
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="VNx-un-2iu">
23+
<rect key="frame" x="0.0" y="0.0" width="414" height="702"/>
24+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
25+
<color key="textColor" systemColor="labelColor"/>
26+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
27+
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
28+
</textView>
29+
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="w0H-Uz-LnS">
30+
<rect key="frame" x="0.0" y="702" width="414" height="34"/>
31+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
32+
<textInputTraits key="textInputTraits"/>
33+
<connections>
34+
<outlet property="delegate" destination="BYZ-38-t0r" id="q8g-10-DAx"/>
35+
</connections>
36+
</textField>
37+
</subviews>
38+
</stackView>
39+
</subviews>
40+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
41+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
42+
<constraints>
43+
<constraint firstItem="7On-uZ-aZ1" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="C3A-52-0VG"/>
44+
<constraint firstItem="7On-uZ-aZ1" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="DL6-In-VJX"/>
45+
<constraint firstItem="7On-uZ-aZ1" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="Uz6-RV-J09"/>
46+
<constraint firstItem="7On-uZ-aZ1" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="hqE-Lf-IVf"/>
47+
</constraints>
48+
</view>
49+
<connections>
50+
<outlet property="bottomConstraint" destination="Uz6-RV-J09" id="5XP-UF-ulk"/>
51+
<outlet property="stackView" destination="7On-uZ-aZ1" id="xYV-pe-Rwh"/>
52+
<outlet property="textField" destination="w0H-Uz-LnS" id="gPz-bO-79O"/>
53+
<outlet property="textView" destination="VNx-un-2iu" id="Eyq-0U-0ku"/>
54+
</connections>
55+
</viewController>
56+
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
57+
</objects>
58+
<point key="canvasLocation" x="139" y="121"/>
59+
</scene>
60+
</scenes>
61+
<resources>
62+
<systemColor name="labelColor">
63+
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
64+
</systemColor>
65+
<systemColor name="systemBackgroundColor">
66+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
67+
</systemColor>
68+
</resources>
69+
</document>

Peertalk Swift Example/Info.plist

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
<key>LSRequiresIPhoneOS</key>
22+
<true/>
23+
<key>UIApplicationSceneManifest</key>
24+
<dict>
25+
<key>UIApplicationSupportsMultipleScenes</key>
26+
<false/>
27+
<key>UISceneConfigurations</key>
28+
<dict>
29+
<key>UIWindowSceneSessionRoleApplication</key>
30+
<array>
31+
<dict>
32+
<key>UISceneConfigurationName</key>
33+
<string>Default Configuration</string>
34+
<key>UISceneDelegateClassName</key>
35+
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
36+
<key>UISceneStoryboardFile</key>
37+
<string>Main</string>
38+
</dict>
39+
</array>
40+
</dict>
41+
</dict>
42+
<key>UIApplicationSupportsIndirectInputEvents</key>
43+
<true/>
44+
<key>UILaunchStoryboardName</key>
45+
<string>LaunchScreen</string>
46+
<key>UIMainStoryboardFile</key>
47+
<string>Main</string>
48+
<key>UIRequiredDeviceCapabilities</key>
49+
<array>
50+
<string>armv7</string>
51+
</array>
52+
<key>UISupportedInterfaceOrientations</key>
53+
<array>
54+
<string>UIInterfaceOrientationPortrait</string>
55+
<string>UIInterfaceOrientationLandscapeLeft</string>
56+
<string>UIInterfaceOrientationLandscapeRight</string>
57+
</array>
58+
<key>UISupportedInterfaceOrientations~ipad</key>
59+
<array>
60+
<string>UIInterfaceOrientationPortrait</string>
61+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
62+
<string>UIInterfaceOrientationLandscapeLeft</string>
63+
<string>UIInterfaceOrientationLandscapeRight</string>
64+
</array>
65+
</dict>
66+
</plist>

0 commit comments

Comments
 (0)