浏览代码

Add initial content for testApp

xcbosa mbp16 2 年之前
父节点
当前提交
9fca9bafda
共有 4 个文件被更改,包括 54 次插入1 次删除
  1. 1 0
      Interop/TypeMapping.swift
  2. 42 0
      TestApp/InitialContent.xct
  3. 7 1
      TestApp/RootViewController.m
  4. 4 0
      XCTreeLang.xcodeproj/project.pbxproj

+ 1 - 0
Interop/TypeMapping.swift

@@ -1,6 +1,7 @@
 //
 //  Dynamic
 //  Created by Mhd Hejazi on 4/18/20.
+//  Modify by XCBOSA on 6/3/23
 //  Copyright © 2020 Samabox. All rights reserved.
 //
 

+ 42 - 0
TestApp/InitialContent.xct

@@ -0,0 +1,42 @@
+paragraph fib(inArray: array maxInputNumber: max) {
+    array.addObject(0)
+    for i in range(1 max) {
+        switch i {
+            lessthan 2 { nextthan }
+            equalthan 2 {
+                array.addObject(i)
+            }
+            else {
+                set last = array.objectAtIndex(minus(i 1))
+                set prev = array.objectAtIndex(minus(i 2))
+                set newValue = add(last prev)
+                array.addObject(newValue)
+            }
+        }
+    }
+}
+
+paragraph main {
+    NSMutableArray array { }
+    fib(inArray: array maxInputNumber: 10)
+    set id = 0
+    for it in array {
+        switch id {
+            equalthan 0 { continue }
+            else {
+                logn("fib(" id ") =" it)
+            }
+        }
+        set id = add(id 1)
+    }
+    setUpPreview()
+}
+
+paragraph setUpPreview {
+    export previewViewController
+    XCTLViewController previewViewController { } {
+        .view.backgroundColor = UIColor.cyanColor
+    }
+}
+
+main()

+ 7 - 1
TestApp/RootViewController.m

@@ -94,7 +94,13 @@ char *kRootViewControllerKVOKey = "kRootViewControllerKVOKey";
     if (!_sourceTextView) {
         _sourceTextView = [self makeTextView];
         _sourceTextView.backgroundColor = UIColor.systemBackgroundColor;
-        _sourceTextView.text = [NSUserDefaults.standardUserDefaults stringForKey:@"code"];
+        NSString *savedCode = [NSUserDefaults.standardUserDefaults stringForKey:@"code"];
+        if (savedCode == nil || savedCode.length == 0) {
+            savedCode = [NSString stringWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"InitialContent" ofType:@"xct"]
+                                                  encoding:NSUTF8StringEncoding
+                                                     error:nil];
+        }
+        _sourceTextView.text = savedCode;
         _sourceTextView.delegate = self;
     }
     return _sourceTextView;

+ 4 - 0
XCTreeLang.xcodeproj/project.pbxproj

@@ -67,6 +67,7 @@
 		756916B52A2B7D20005FF14B /* XCTLInvocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 756916B32A2B7D20005FF14B /* XCTLInvocation.m */; };
 		756916B92A2B86AA005FF14B /* XCTLSwiftInvocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756916B82A2B86AA005FF14B /* XCTLSwiftInvocation.swift */; };
 		756916BD2A2B91E7005FF14B /* NSArray+Enumerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756916BC2A2B91E7005FF14B /* NSArray+Enumerator.swift */; };
+		756916BF2A2B97BF005FF14B /* InitialContent.xct in Resources */ = {isa = PBXBuildFile; fileRef = 756916BE2A2B97BF005FF14B /* InitialContent.xct */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -158,6 +159,7 @@
 		756916B32A2B7D20005FF14B /* XCTLInvocation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XCTLInvocation.m; sourceTree = "<group>"; };
 		756916B82A2B86AA005FF14B /* XCTLSwiftInvocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTLSwiftInvocation.swift; sourceTree = "<group>"; };
 		756916BC2A2B91E7005FF14B /* NSArray+Enumerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSArray+Enumerator.swift"; sourceTree = "<group>"; };
+		756916BE2A2B97BF005FF14B /* InitialContent.xct */ = {isa = PBXFileReference; lastKnownFileType = text; path = InitialContent.xct; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -297,6 +299,7 @@
 				7520C4412A283CA70010E7F8 /* AppDelegate.m */,
 				7520C4462A283CA70010E7F8 /* RootViewController.h */,
 				7520C4472A283CA70010E7F8 /* RootViewController.m */,
+				756916BE2A2B97BF005FF14B /* InitialContent.xct */,
 				7520C44C2A283CA80010E7F8 /* Assets.xcassets */,
 				7520C44E2A283CA80010E7F8 /* LaunchScreen.storyboard */,
 				7520C4512A283CA80010E7F8 /* Info.plist */,
@@ -465,6 +468,7 @@
 			buildActionMask = 2147483647;
 			files = (
 				7520C4502A283CA80010E7F8 /* LaunchScreen.storyboard in Resources */,
+				756916BF2A2B97BF005FF14B /* InitialContent.xct in Resources */,
 				7520C44D2A283CA80010E7F8 /* Assets.xcassets in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;