Commit 7545e30d authored by Bruno Coelho's avatar Bruno Coelho

Simplify iOS example

parent 52f4e25e
#import "TXSItemList.h"
#import "TXSSortItems.h"
#import "TextSort-Swift.h"
#import "TXSTextboxListenerImpl.h"
#import "TXSViewController.h"
#import "TXSTextboxListener.h"
......@@ -12,6 +13,8 @@
@property (nonatomic) IBOutlet UIButton *button;
@property (nonatomic) IBOutlet UISwitch *switchDebugMode;
@end
@implementation TXSViewController {
......@@ -33,11 +36,28 @@
action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
// Create the Objective-C TXSTextboxListener
_textboxListener = [[TXSTextboxListenerImpl alloc] initWithUITextView:self.textView];
[self createSorter];
}
-(void)createSorter
{
if (_switchDebugMode.isOn) {
// Create the Swift TXSTextboxListener
_textboxListener = [[TXSTextboxListenerDebugableImpl alloc] initWithUITextView:self.textView];
}
else {
// Create the Objective-C TXSTextboxListener
_textboxListener = [[TXSTextboxListenerImpl alloc] initWithUITextView:self.textView];
}
_sortItemInterface = [TXSSortItems createWithListener:_textboxListener];
}
-(IBAction)toggleDebugMode:(id)sender
{
[self createSorter];
}
- (IBAction)sort:(id)sender
{
[self sortWithOrder:TXSSortOrderAscending];
......
......@@ -8,7 +8,7 @@
import UIKit
@objc class TXSTextboxListenerImpl : NSObject, TXSTextboxListener {
@objc class TXSTextboxListenerDebugableImpl : NSObject, TXSTextboxListener {
private var textView_: UITextView
@objc(initWithUITextView:)
......@@ -17,6 +17,8 @@ import UIKit
}
@objc func update(_ items: TXSItemList) {
textView_.text = items.items.joined(separator: "\n")
let string = items.items.joined(separator: "\n")
print("TXSTextboxListenerDebugableImpl -> update \n\(string)")
textView_.text = string
}
}
......@@ -17,7 +17,7 @@
65D7FDFB19AD0CDF0038F82F /* TXSAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 65D7FDF519AD0CDF0038F82F /* TXSAppDelegate.m */; };
65D7FDFC19AD0CDF0038F82F /* TXSTextboxListenerImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = 65D7FDF719AD0CDF0038F82F /* TXSTextboxListenerImpl.m */; };
65D7FDFD19AD0CDF0038F82F /* TXSViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 65D7FDF919AD0CDF0038F82F /* TXSViewController.m */; };
A546A26E1E72FBAF004A8BBD /* TXSTextboxListenerImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = A546A26D1E72FBAF004A8BBD /* TXSTextboxListenerImpl.swift */; };
A546A26E1E72FBAF004A8BBD /* TXSTextboxListenerDebugableImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = A546A26D1E72FBAF004A8BBD /* TXSTextboxListenerDebugableImpl.swift */; };
B003051919B70561008E1F67 /* libdjinni_objc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B003051819B70561008E1F67 /* libdjinni_objc.a */; };
B097B6BC19B1C07E0047653A /* libtextsort_objc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B097B6BB19B1C07E0047653A /* libtextsort_objc.a */; };
/* End PBXBuildFile section */
......@@ -39,7 +39,7 @@
65D7FDF719AD0CDF0038F82F /* TXSTextboxListenerImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TXSTextboxListenerImpl.m; sourceTree = "<group>"; };
65D7FDF819AD0CDF0038F82F /* TXSViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TXSViewController.h; sourceTree = "<group>"; };
65D7FDF919AD0CDF0038F82F /* TXSViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TXSViewController.m; sourceTree = "<group>"; };
A546A26D1E72FBAF004A8BBD /* TXSTextboxListenerImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TXSTextboxListenerImpl.swift; path = "../handwritten-src/swift/TXSTextboxListenerImpl.swift"; sourceTree = "<group>"; };
A546A26D1E72FBAF004A8BBD /* TXSTextboxListenerDebugableImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TXSTextboxListenerDebugableImpl.swift; path = "../handwritten-src/swift/TXSTextboxListenerDebugableImpl.swift"; sourceTree = "<group>"; };
B003051819B70561008E1F67 /* libdjinni_objc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libdjinni_objc.a; path = "../../support-lib/build/Debug-iphoneos/libdjinni_objc.a"; sourceTree = "<group>"; };
B097B6BB19B1C07E0047653A /* libtextsort_objc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtextsort_objc.a; path = "../../build/Debug-iphoneos/libtextsort_objc.a"; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -129,7 +129,7 @@
A546A26A1E72F967004A8BBD /* handwritten-swift */ = {
isa = PBXGroup;
children = (
A546A26D1E72FBAF004A8BBD /* TXSTextboxListenerImpl.swift */,
A546A26D1E72FBAF004A8BBD /* TXSTextboxListenerDebugableImpl.swift */,
);
name = "handwritten-swift";
sourceTree = "<group>";
......@@ -208,7 +208,7 @@
65D7FDFC19AD0CDF0038F82F /* TXSTextboxListenerImpl.m in Sources */,
65D7FDFB19AD0CDF0038F82F /* TXSAppDelegate.m in Sources */,
65D7FDFD19AD0CDF0038F82F /* TXSViewController.m in Sources */,
A546A26E1E72FBAF004A8BBD /* TXSTextboxListenerImpl.swift in Sources */,
A546A26E1E72FBAF004A8BBD /* TXSTextboxListenerDebugableImpl.swift in Sources */,
65D7FDFA19AD0CDF0038F82F /* main.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7531" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
......@@ -15,52 +19,69 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="Type the lines to sort" translatesAutoresizingMaskIntoConstraints="NO" id="GOB-Ok-Z2R">
<rect key="frame" x="16" y="28" width="288" height="482"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<rect key="frame" x="16" y="28" width="343" height="531"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="A93-rB-AZ4">
<rect key="frame" x="54" y="518" width="60" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="A93-rB-AZ4">
<rect key="frame" x="105.5" y="567" width="30" height="30"/>
<state key="normal" title="Sort">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="sort:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="JmD-7I-e8t"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="81n-2H-7fH">
<rect key="frame" x="104" y="518" width="113" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="81n-2H-7fH">
<rect key="frame" x="143.5" y="567" width="88" height="30"/>
<state key="normal" title="Reverse Sort">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="reverseSort:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="3ph-FD-T7F"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cv7-dA-P8a">
<rect key="frame" x="225" y="518" width="60" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cv7-dA-P8a">
<rect key="frame" x="239.5" y="567" width="57" height="30"/>
<state key="normal" title="Random">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="randomSort:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="Qm2-PQ-ghk"/>
</connections>
</button>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="DNu-UL-kyQ">
<rect key="frame" x="16" y="612" width="51" height="31"/>
<connections>
<action selector="toggleDebugMode:" destination="vXZ-lx-hvc" eventType="valueChanged" id="saA-Gv-pMA"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Debug mode" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GQQ-Bh-tdD">
<rect key="frame" x="73" y="617" width="286" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="cv7-dA-P8a" firstAttribute="leading" secondItem="81n-2H-7fH" secondAttribute="trailing" constant="8" id="6k6-kS-Uv4"/>
<constraint firstItem="81n-2H-7fH" firstAttribute="baseline" secondItem="cv7-dA-P8a" secondAttribute="baseline" id="EDF-c5-6UY"/>
<constraint firstItem="GOB-Ok-Z2R" firstAttribute="trailing" secondItem="kh9-bI-dsS" secondAttribute="trailingMargin" id="FcW-gp-TKr"/>
<constraint firstItem="cv7-dA-P8a" firstAttribute="top" secondItem="GOB-Ok-Z2R" secondAttribute="bottom" constant="8" id="LWK-fr-cJv"/>
<constraint firstItem="81n-2H-7fH" firstAttribute="leading" secondItem="A93-rB-AZ4" secondAttribute="trailing" constant="8" id="M4F-4D-BXj"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="81n-2H-7fH" secondAttribute="bottom" constant="20" id="Skf-gJ-Pvn"/>
<constraint firstItem="DNu-UL-kyQ" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="O7c-MW-i3e"/>
<constraint firstItem="DNu-UL-kyQ" firstAttribute="centerY" secondItem="GQQ-Bh-tdD" secondAttribute="centerY" id="OmV-xh-MjX"/>
<constraint firstItem="GQQ-Bh-tdD" firstAttribute="top" secondItem="81n-2H-7fH" secondAttribute="bottom" constant="20" id="P8h-HO-l5l"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="81n-2H-7fH" secondAttribute="bottom" constant="70" id="Skf-gJ-Pvn"/>
<constraint firstAttribute="centerX" secondItem="81n-2H-7fH" secondAttribute="centerX" id="dPr-yc-eNh"/>
<constraint firstItem="GQQ-Bh-tdD" firstAttribute="leading" secondItem="DNu-UL-kyQ" secondAttribute="trailing" constant="8" id="jez-lS-j5y"/>
<constraint firstAttribute="trailingMargin" secondItem="GQQ-Bh-tdD" secondAttribute="trailing" id="pDH-RO-DoJ"/>
<constraint firstItem="GOB-Ok-Z2R" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="8" id="r9O-jI-RXe"/>
<constraint firstItem="81n-2H-7fH" firstAttribute="baseline" secondItem="A93-rB-AZ4" secondAttribute="baseline" id="sDL-eI-t03"/>
<constraint firstItem="GOB-Ok-Z2R" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="ykx-tI-cFm"/>
......@@ -69,16 +90,18 @@
<navigationItem key="navigationItem" id="LTz-Tk-BIg"/>
<connections>
<outlet property="button" destination="A93-rB-AZ4" id="WYY-v8-55y"/>
<outlet property="switchDebugMode" destination="DNu-UL-kyQ" id="zWL-2v-leX"/>
<outlet property="textView" destination="GOB-Ok-Z2R" id="fKy-K6-TxA"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="26.5" y="34.5"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
<simulatedScreenMetrics key="destination" type="retina4_7.fullscreen"/>
</simulatedMetricsContainer>
</document>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment