提交 4e9ec5a1 编写于 作者: L libb

add swift、ld demo

Change-Id: Ia5ed3f134af8ebbb0a254dbf2b32fb96cc5beb95
上级 eacabb47
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
F38926B524A86D80002F724A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F38926B424A86D80002F724A /* AppDelegate.m */; };
F38926B824A86D80002F724A /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F38926B724A86D80002F724A /* SceneDelegate.m */; };
F38926BB24A86D80002F724A /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F38926BA24A86D80002F724A /* ViewController.m */; };
F38926BE24A86D80002F724A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F38926BC24A86D80002F724A /* Main.storyboard */; };
F38926C024A86D85002F724A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F38926BF24A86D85002F724A /* Assets.xcassets */; };
F38926C324A86D85002F724A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F38926C124A86D85002F724A /* LaunchScreen.storyboard */; };
F38926C624A86D85002F724A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F38926C524A86D85002F724A /* main.m */; };
F38926CD24A87425002F724A /* libtest.so in Resources */ = {isa = PBXBuildFile; fileRef = F38926CC24A87425002F724A /* libtest.so */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
F38926B024A86D80002F724A /* ld01.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ld01.app; sourceTree = BUILT_PRODUCTS_DIR; };
F38926B324A86D80002F724A /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
F38926B424A86D80002F724A /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
F38926B624A86D80002F724A /* SceneDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SceneDelegate.h; sourceTree = "<group>"; };
F38926B724A86D80002F724A /* SceneDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SceneDelegate.m; sourceTree = "<group>"; };
F38926B924A86D80002F724A /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
F38926BA24A86D80002F724A /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
F38926BD24A86D80002F724A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
F38926BF24A86D85002F724A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
F38926C224A86D85002F724A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
F38926C424A86D85002F724A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F38926C524A86D85002F724A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
F38926CC24A87425002F724A /* libtest.so */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libtest.so; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
F38926AD24A86D80002F724A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
F38926A724A86D80002F724A = {
isa = PBXGroup;
children = (
F38926B224A86D80002F724A /* ld01 */,
F38926B124A86D80002F724A /* Products */,
);
sourceTree = "<group>";
};
F38926B124A86D80002F724A /* Products */ = {
isa = PBXGroup;
children = (
F38926B024A86D80002F724A /* ld01.app */,
);
name = Products;
sourceTree = "<group>";
};
F38926B224A86D80002F724A /* ld01 */ = {
isa = PBXGroup;
children = (
F38926CC24A87425002F724A /* libtest.so */,
F38926B324A86D80002F724A /* AppDelegate.h */,
F38926B424A86D80002F724A /* AppDelegate.m */,
F38926B624A86D80002F724A /* SceneDelegate.h */,
F38926B724A86D80002F724A /* SceneDelegate.m */,
F38926B924A86D80002F724A /* ViewController.h */,
F38926BA24A86D80002F724A /* ViewController.m */,
F38926BC24A86D80002F724A /* Main.storyboard */,
F38926BF24A86D85002F724A /* Assets.xcassets */,
F38926C124A86D85002F724A /* LaunchScreen.storyboard */,
F38926C424A86D85002F724A /* Info.plist */,
F38926C524A86D85002F724A /* main.m */,
);
path = ld01;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
F38926AF24A86D80002F724A /* ld01 */ = {
isa = PBXNativeTarget;
buildConfigurationList = F38926C924A86D85002F724A /* Build configuration list for PBXNativeTarget "ld01" */;
buildPhases = (
F38926AC24A86D80002F724A /* Sources */,
F38926AD24A86D80002F724A /* Frameworks */,
F38926AE24A86D80002F724A /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = ld01;
productName = ld01;
productReference = F38926B024A86D80002F724A /* ld01.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
F38926A824A86D80002F724A /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1140;
ORGANIZATIONNAME = admin;
TargetAttributes = {
F38926AF24A86D80002F724A = {
CreatedOnToolsVersion = 11.4.1;
};
};
};
buildConfigurationList = F38926AB24A86D80002F724A /* Build configuration list for PBXProject "ld01" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = F38926A724A86D80002F724A;
productRefGroup = F38926B124A86D80002F724A /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
F38926AF24A86D80002F724A /* ld01 */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
F38926AE24A86D80002F724A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F38926C324A86D85002F724A /* LaunchScreen.storyboard in Resources */,
F38926CD24A87425002F724A /* libtest.so in Resources */,
F38926C024A86D85002F724A /* Assets.xcassets in Resources */,
F38926BE24A86D80002F724A /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
F38926AC24A86D80002F724A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F38926BB24A86D80002F724A /* ViewController.m in Sources */,
F38926B524A86D80002F724A /* AppDelegate.m in Sources */,
F38926C624A86D85002F724A /* main.m in Sources */,
F38926B824A86D80002F724A /* SceneDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
F38926BC24A86D80002F724A /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
F38926BD24A86D80002F724A /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
F38926C124A86D85002F724A /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
F38926C224A86D85002F724A /* Base */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
F38926C724A86D85002F724A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
};
F38926C824A86D85002F724A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
F38926CA24A86D85002F724A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = ld01/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.ld01;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
F38926CB24A86D85002F724A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = ld01/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.ld01;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
F38926AB24A86D80002F724A /* Build configuration list for PBXProject "ld01" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F38926C724A86D85002F724A /* Debug */,
F38926C824A86D85002F724A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
F38926C924A86D85002F724A /* Build configuration list for PBXNativeTarget "ld01" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F38926CA24A86D85002F724A /* Debug */,
F38926CB24A86D85002F724A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = F38926A824A86D80002F724A /* Project object */;
}
//
// AppDelegate.h
// ld01
//
// Created by on 2020/6/28.
// Copyright © 2020 admin. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@end
//
// AppDelegate.m
// ld01
//
// Created by on 2020/6/28.
// Copyright © 2020 admin. All rights reserved.
//
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
#pragma mark - UISceneSession lifecycle
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
@end
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
//
// SceneDelegate.h
// ld01
//
// Created by on 2020/6/28.
// Copyright © 2020 admin. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>
@property (strong, nonatomic) UIWindow * window;
@end
//
// SceneDelegate.m
// ld01
//
// Created by on 2020/6/28.
// Copyright © 2020 admin. All rights reserved.
//
#import "SceneDelegate.h"
@interface SceneDelegate ()
@end
@implementation SceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
}
- (void)sceneDidDisconnect:(UIScene *)scene {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
}
- (void)sceneDidBecomeActive:(UIScene *)scene {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
- (void)sceneWillResignActive:(UIScene *)scene {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
- (void)sceneWillEnterForeground:(UIScene *)scene {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
- (void)sceneDidEnterBackground:(UIScene *)scene {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
@end
//
// ViewController.h
// ld01
//
// Created by on 2020/6/28.
// Copyright © 2020 admin. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
//
// ViewController.m
// ld01
//
// Created by on 2020/6/28.
// Copyright © 2020 admin. All rights reserved.
//
#import "ViewController.h"
#import <dlfcn.h>
#include <assert.h>
@interface ViewController ()
@property (nonatomic,strong) id runtime_Player;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// [self runtimePlay];
printf("come in\n");
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
NSString* dlPath = [NSString stringWithFormat: @"%@/libtest.so", resourcePath];
const char* cdlpath = [dlPath UTF8String];
void *lib = dlopen("libtest.so", RTLD_LAZY);
void *handler = dlopen(cdlpath, RTLD_LAZY);
printf("dlopen - %sn", dlerror());
assert(handler != NULL);
void (*pTest)(int);
pTest = (void (*)(int))dlsym(handler, "add");
(*pTest)(10);
dlclose(handler);
printf("go out\n");
return;
NSString * const* foregroundConstant = (NSString * const *) dlsym(RTLD_DEFAULT, "UIApplicationWillEnterForegroundNotification");
NSLog(@"foregroundConstant:%@",*foregroundConstant);
if (foregroundConstant) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(enteringForeground)
name:*foregroundConstant
object:nil];
}
}
- (void)runtimePlay{
// 获取音乐资源路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"rain" ofType:@"mp3"];
// 加载库到当前运行程序
void *lib = dlopen("/System/Library/Frameworks/AVFoundation.framework/AVFoundation", RTLD_LAZY);
if (lib) {
// 获取类名称
Class playerClass = NSClassFromString(@"AVAudioPlayer");
// 获取函数方法
SEL selector = NSSelectorFromString(@"initWithData:error:");
// 调用实例化对象方法
_runtime_Player = [[playerClass alloc] performSelector:selector withObject:[NSData dataWithContentsOfFile:path] withObject:nil];
// 获取函数方法
selector = NSSelectorFromString(@"play");
// 调用播放方法
[_runtime_Player performSelector:selector];
NSLog(@"动态加载播放");
}
}
- (void) enteringForeground {
NSLog(@"enteringForeground");
}
- (void) dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
//
// main.m
// ld01
//
// Created by on 2020/6/28.
// Copyright © 2020 admin. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
NSString * appDelegateClassName;
@autoreleasepool {
// Setup code that might create autoreleased objects goes here.
appDelegateClassName = NSStringFromClass([AppDelegate class]);
}
return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}
文件已添加
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dlfcn.h> /* 必须加这个头文件 */
#include <assert.h>
int main(int argc, char *argv[])
{
printf("come in\n");
void *handler = dlopen("libtest.so", RTLD_NOW);
assert(handler != NULL);
void (*pTest)(int);
pTest = (void (*)(int))dlsym(handler, "add");
(*pTest)(10);
dlclose(handler);
printf("go out\n");
return 0;
}
#include <stdio.h>
#ifdef __cplusplus
extern "C"{
#endif
void add(int num)
{
printf("*****************************************\n");
printf("This is ok, the number is okay. %d\n", num);
printf("*****************************************\n");
}
#ifdef __cplusplus
}
#endif
参考https://github.com/captain-charisma/GhostChallenge
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
F3FD53F824EBA848000462CD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD53F724EBA848000462CD /* AppDelegate.swift */; };
F3FD53FA24EBA848000462CD /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD53F924EBA848000462CD /* SceneDelegate.swift */; };
F3FD53FC24EBA848000462CD /* MasterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD53FB24EBA848000462CD /* MasterViewController.swift */; };
F3FD53FE24EBA848000462CD /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD53FD24EBA848000462CD /* DetailViewController.swift */; };
F3FD540124EBA848000462CD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F3FD53FF24EBA848000462CD /* Main.storyboard */; };
F3FD540324EBA84E000462CD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F3FD540224EBA84E000462CD /* Assets.xcassets */; };
F3FD540624EBA84E000462CD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F3FD540424EBA84E000462CD /* LaunchScreen.storyboard */; };
F3FD540E24EBA8FF000462CD /* MainTableViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD540D24EBA8FF000462CD /* MainTableViewDataSource.swift */; };
F3FD541324EBD162000462CD /* Resource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD541224EBD162000462CD /* Resource.swift */; };
F3FD541524EBD391000462CD /* JSONPlaceholder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD541424EBD391000462CD /* JSONPlaceholder.swift */; };
F3FD541724ECB0BC000462CD /* WebService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD541624ECB0BC000462CD /* WebService.swift */; };
F3FD541A24ECB542000462CD /* Dream.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD541924ECB542000462CD /* Dream.swift */; };
F3FD541C24ECB82A000462CD /* DreamData.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD541B24ECB82A000462CD /* DreamData.swift */; };
F3FD541F24ECBC9B000462CD /* DateFmt.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD541E24ECBC9B000462CD /* DateFmt.swift */; };
F3FD542124ECBCB1000462CD /* RandomNumberGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD542024ECBCB1000462CD /* RandomNumberGenerator.swift */; };
F3FD542324ECC313000462CD /* NotificationName_Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FD542224ECC313000462CD /* NotificationName_Ext.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
F3FD53F424EBA848000462CD /* swift01.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = swift01.app; sourceTree = BUILT_PRODUCTS_DIR; };
F3FD53F724EBA848000462CD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
F3FD53F924EBA848000462CD /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
F3FD53FB24EBA848000462CD /* MasterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterViewController.swift; sourceTree = "<group>"; };
F3FD53FD24EBA848000462CD /* DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = "<group>"; };
F3FD540024EBA848000462CD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
F3FD540224EBA84E000462CD /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
F3FD540524EBA84E000462CD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
F3FD540724EBA84E000462CD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F3FD540D24EBA8FF000462CD /* MainTableViewDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewDataSource.swift; sourceTree = "<group>"; };
F3FD541224EBD162000462CD /* Resource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resource.swift; sourceTree = "<group>"; };
F3FD541424EBD391000462CD /* JSONPlaceholder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONPlaceholder.swift; sourceTree = "<group>"; };
F3FD541624ECB0BC000462CD /* WebService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebService.swift; sourceTree = "<group>"; };
F3FD541924ECB542000462CD /* Dream.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dream.swift; sourceTree = "<group>"; };
F3FD541B24ECB82A000462CD /* DreamData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DreamData.swift; sourceTree = "<group>"; };
F3FD541E24ECBC9B000462CD /* DateFmt.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateFmt.swift; sourceTree = "<group>"; };
F3FD542024ECBCB1000462CD /* RandomNumberGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RandomNumberGenerator.swift; sourceTree = "<group>"; };
F3FD542224ECC313000462CD /* NotificationName_Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationName_Ext.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
F3FD53F124EBA848000462CD /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
F3FD53EB24EBA848000462CD = {
isa = PBXGroup;
children = (
F3FD53F624EBA848000462CD /* swift01 */,
F3FD53F524EBA848000462CD /* Products */,
);
sourceTree = "<group>";
};
F3FD53F524EBA848000462CD /* Products */ = {
isa = PBXGroup;
children = (
F3FD53F424EBA848000462CD /* swift01.app */,
);
name = Products;
sourceTree = "<group>";
};
F3FD53F624EBA848000462CD /* swift01 */ = {
isa = PBXGroup;
children = (
F3FD541D24ECBC9B000462CD /* Util */,
F3FD541824ECB533000462CD /* Model */,
F3FD53F724EBA848000462CD /* AppDelegate.swift */,
F3FD53F924EBA848000462CD /* SceneDelegate.swift */,
F3FD53FB24EBA848000462CD /* MasterViewController.swift */,
F3FD541224EBD162000462CD /* Resource.swift */,
F3FD541624ECB0BC000462CD /* WebService.swift */,
F3FD541424EBD391000462CD /* JSONPlaceholder.swift */,
F3FD540D24EBA8FF000462CD /* MainTableViewDataSource.swift */,
F3FD542224ECC313000462CD /* NotificationName_Ext.swift */,
F3FD53FD24EBA848000462CD /* DetailViewController.swift */,
F3FD53FF24EBA848000462CD /* Main.storyboard */,
F3FD540224EBA84E000462CD /* Assets.xcassets */,
F3FD540424EBA84E000462CD /* LaunchScreen.storyboard */,
F3FD540724EBA84E000462CD /* Info.plist */,
);
path = swift01;
sourceTree = "<group>";
};
F3FD541824ECB533000462CD /* Model */ = {
isa = PBXGroup;
children = (
F3FD541924ECB542000462CD /* Dream.swift */,
F3FD541B24ECB82A000462CD /* DreamData.swift */,
);
path = Model;
sourceTree = "<group>";
};
F3FD541D24ECBC9B000462CD /* Util */ = {
isa = PBXGroup;
children = (
F3FD541E24ECBC9B000462CD /* DateFmt.swift */,
F3FD542024ECBCB1000462CD /* RandomNumberGenerator.swift */,
);
path = Util;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
F3FD53F324EBA848000462CD /* swift01 */ = {
isa = PBXNativeTarget;
buildConfigurationList = F3FD540A24EBA84E000462CD /* Build configuration list for PBXNativeTarget "swift01" */;
buildPhases = (
F3FD53F024EBA848000462CD /* Sources */,
F3FD53F124EBA848000462CD /* Frameworks */,
F3FD53F224EBA848000462CD /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = swift01;
productName = swift01;
productReference = F3FD53F424EBA848000462CD /* swift01.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
F3FD53EC24EBA848000462CD /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1140;
LastUpgradeCheck = 1140;
ORGANIZATIONNAME = admin;
TargetAttributes = {
F3FD53F324EBA848000462CD = {
CreatedOnToolsVersion = 11.4.1;
};
};
};
buildConfigurationList = F3FD53EF24EBA848000462CD /* Build configuration list for PBXProject "swift01" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = F3FD53EB24EBA848000462CD;
productRefGroup = F3FD53F524EBA848000462CD /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
F3FD53F324EBA848000462CD /* swift01 */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
F3FD53F224EBA848000462CD /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F3FD540624EBA84E000462CD /* LaunchScreen.storyboard in Resources */,
F3FD540324EBA84E000462CD /* Assets.xcassets in Resources */,
F3FD540124EBA848000462CD /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
F3FD53F024EBA848000462CD /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F3FD541F24ECBC9B000462CD /* DateFmt.swift in Sources */,
F3FD541724ECB0BC000462CD /* WebService.swift in Sources */,
F3FD53F824EBA848000462CD /* AppDelegate.swift in Sources */,
F3FD542324ECC313000462CD /* NotificationName_Ext.swift in Sources */,
F3FD53FA24EBA848000462CD /* SceneDelegate.swift in Sources */,
F3FD541A24ECB542000462CD /* Dream.swift in Sources */,
F3FD53FC24EBA848000462CD /* MasterViewController.swift in Sources */,
F3FD540E24EBA8FF000462CD /* MainTableViewDataSource.swift in Sources */,
F3FD541524EBD391000462CD /* JSONPlaceholder.swift in Sources */,
F3FD53FE24EBA848000462CD /* DetailViewController.swift in Sources */,
F3FD541324EBD162000462CD /* Resource.swift in Sources */,
F3FD541C24ECB82A000462CD /* DreamData.swift in Sources */,
F3FD542124ECBCB1000462CD /* RandomNumberGenerator.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
F3FD53FF24EBA848000462CD /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
F3FD540024EBA848000462CD /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
F3FD540424EBA84E000462CD /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
F3FD540524EBA84E000462CD /* Base */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
F3FD540824EBA84E000462CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
F3FD540924EBA84E000462CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
F3FD540B24EBA84E000462CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = swift01/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.swift01;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
F3FD540C24EBA84E000462CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = swift01/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.test.swift01;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
F3FD53EF24EBA848000462CD /* Build configuration list for PBXProject "swift01" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F3FD540824EBA84E000462CD /* Debug */,
F3FD540924EBA84E000462CD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
F3FD540A24EBA84E000462CD /* Build configuration list for PBXNativeTarget "swift01" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F3FD540B24EBA84E000462CD /* Debug */,
F3FD540C24EBA84E000462CD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = F3FD53EC24EBA848000462CD /* Project object */;
}
//
// AppDelegate.swift
// swift01
//
// Created by on 2020/8/18.
// Copyright © 2020 admin. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="H1p-Uh-vWS">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Master-->
<scene sceneID="pY4-Hu-kfo">
<objects>
<navigationController title="Master" id="RMx-3f-FxP" sceneMemberID="viewController">
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="Pmd-2v-anx">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="7bK-jq-Zjz" kind="relationship" relationship="rootViewController" id="tsl-Nk-0bq"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="8fS-aE-onr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-38" y="-630"/>
</scene>
<!--Detail-->
<scene sceneID="yUG-lL-AsK">
<objects>
<viewController title="Detail" id="JEX-9P-axG" customClass="DetailViewController" customModule="swift01" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="svH-Pt-448">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="Detail view content goes here" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="0XM-y9-sOw">
<rect key="frame" x="20" y="322" width="374" height="20.5"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="0XM-y9-sOw" firstAttribute="top" secondItem="VUw-jc-0yf" secondAttribute="top" constant="234" id="9eQ-1s-0ID"/>
<constraint firstItem="0XM-y9-sOw" firstAttribute="leading" secondItem="VUw-jc-0yf" secondAttribute="leading" constant="20" id="D8o-Ng-wBm"/>
<constraint firstItem="VUw-jc-0yf" firstAttribute="trailing" secondItem="0XM-y9-sOw" secondAttribute="trailing" constant="20" id="n9A-Li-LeK"/>
<constraint firstItem="VUw-jc-0yf" firstAttribute="bottom" secondItem="0XM-y9-sOw" secondAttribute="bottom" constant="519.5" id="wkQ-SZ-zsl"/>
</constraints>
<viewLayoutGuide key="safeArea" id="VUw-jc-0yf"/>
</view>
<toolbarItems/>
<navigationItem key="navigationItem" title="Detail" id="mOI-FS-AaM"/>
<connections>
<outlet property="detailDescriptionLabel" destination="0XM-y9-sOw" id="deQ-Na-JPF"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="FJe-Yq-33r" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="708.69565217391312" y="128.57142857142856"/>
</scene>
<!--Split View Controller-->
<scene sceneID="Nki-YV-4Qg">
<objects>
<splitViewController id="H1p-Uh-vWS" sceneMemberID="viewController">
<toolbarItems/>
<connections>
<segue destination="RMx-3f-FxP" kind="relationship" relationship="masterViewController" id="BlO-5A-QYV"/>
<segue destination="vC3-pB-5Vb" kind="relationship" relationship="detailViewController" id="Tll-UG-LXB"/>
</connections>
</splitViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="cZU-Oi-B1e" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-856" y="-330"/>
</scene>
<!--Master-->
<scene sceneID="smW-Zh-WAh">
<objects>
<tableViewController title="Master" clearsSelectionOnViewWillAppear="NO" id="7bK-jq-Zjz" customClass="MasterViewController" customModule="swift01" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="r7i-6Z-zg0">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="Arm-wq-HPj" style="IBUITableViewCellStyleDefault" id="WCw-Qf-5nD">
<rect key="frame" x="0.0" y="28" width="414" height="47.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="WCw-Qf-5nD" id="37f-cq-3Eg">
<rect key="frame" x="0.0" y="0.0" width="414" height="47.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Arm-wq-HPj">
<rect key="frame" x="20" y="0.0" width="374" height="47.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</label>
</subviews>
</tableViewCellContentView>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<connections>
<segue destination="vC3-pB-5Vb" kind="showDetail" identifier="showDetail" id="6S0-TO-JiA"/>
</connections>
</tableViewCell>
</prototypes>
<sections/>
<connections>
<outlet property="dataSource" destination="7bK-jq-Zjz" id="Gho-Na-rnu"/>
<outlet property="delegate" destination="7bK-jq-Zjz" id="RA6-mI-bju"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Master" id="Zdf-7t-Un8"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Rux-fX-hf1" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="709" y="-630"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="r7l-gg-dq7">
<objects>
<navigationController id="vC3-pB-5Vb" sceneMemberID="viewController">
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="DjV-YW-jjY">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="JEX-9P-axG" kind="relationship" relationship="rootViewController" id="GKi-kA-LjT"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="SLD-UC-DBI" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-45" y="129"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="6S0-TO-JiA"/>
</inferredMetricsTieBreakers>
</document>
//
// DetailViewController.swift
// swift01
//
// Created by on 2020/8/18.
// Copyright © 2020 admin. All rights reserved.
//
import UIKit
class DetailViewController: UIViewController {
@IBOutlet weak var detailDescriptionLabel: UILabel!
func configureView() {
// Update the user interface for the detail item.
if let detail = detailItem {
if let label = detailDescriptionLabel {
label.text = detail.description
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
configureView()
}
var detailItem: Dream? {
didSet {
// Update the view.
configureView()
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UIStatusBarTintParameters</key>
<dict>
<key>UINavigationBar</key>
<dict>
<key>Style</key>
<string>UIBarStyleDefault</string>
<key>Translucent</key>
<false/>
</dict>
</dict>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
//
// JSONPlaceholder.swift
// swift01
//
// Created by on 2020/8/18.
// Copyright © 2020 admin. All rights reserved.
//
import Foundation
struct JSONPlaceholder {
static let url = URL(string: "https://jsonplaceholder.typicode.com/posts")
let userID : Int
let id : Int
let title : String
let body : String
enum Keys: String, CodingKey {
case userId
case id
case title
case body
}
}
extension JSONPlaceholder : Decodable {
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: Keys.self)
userID = try values.decode(Int.self, forKey: .userId)
title = try values.decode(String.self, forKey: .title)
id = try values.decode(Int.self, forKey: .id)
body = try values.decode(String.self, forKey: .body)
}
}
extension JSONPlaceholder {
static let all = Resource<[JSONPlaceholder]>(JSONPlaceholder.url!) {
(data) -> [JSONPlaceholder]? in
let posts = try? JSONDecoder().decode([JSONPlaceholder].self, from: data)
return posts
}
}
//
// MainTableViewDataSource.swift
// swift01
//
// Created by on 2020/8/18.
// Copyright © 2020 admin. All rights reserved.
//
import Foundation
import UIKit
class MainTableViewDataSource: NSObject {
let webService = WebService()
var dateMachines = [DateFmt]()
fileprivate func setupDates() {
for _ in 0...13 {
let datefmt = DateFmt(date: Date())
print("===",datefmt)
dateMachines.append(datefmt)
}
}
override init() {
super.init()
setupDates()
getData()
}
}
extension MainTableViewDataSource {
func getData() {
webService.load(resource: JSONPlaceholder.all) { [weak self] (posts) in
guard let placeholder = posts else {return}
// print(placeholder)
_ = self?.convertPlaceholderToDreams(withPosts: placeholder)
NotificationCenter.default.post(name: .dataRetrieved, object: nil)
}
}
func convertPlaceholderToDreams(withPosts placeholders: [JSONPlaceholder]) -> [Dream] {
return placeholders.map { placeholder in
let randomNumber = 1
let dateMachine = dateMachines[randomNumber]
let dream = Dream(title: placeholder.title, dateString: dateMachine.dateString, tags:["happy, funny, sad, awesome"], description: placeholder.body)
ApplicationData.DatabaseData.write(toData: dream)
return dream
}
}
}
//
// MasterViewController.swift
// swift01
//
// Created by on 2020/8/18.
// Copyright © 2020 admin. All rights reserved.
//
import UIKit
class MasterViewController: UITableViewController {
let dataSource = MainTableViewDataSource()
var detailViewController: DetailViewController? = nil
var objects = [Any]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
navigationItem.leftBarButtonItem = editButtonItem
setupNotificationObservers()
let addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(insertNewObject(_:)))
navigationItem.rightBarButtonItem = addButton
if let split = splitViewController {
let controllers = split.viewControllers
detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController as? DetailViewController
}
}
override func viewWillAppear(_ animated: Bool) {
clearsSelectionOnViewWillAppear = splitViewController!.isCollapsed
super.viewWillAppear(animated)
}
@objc
func insertNewObject(_ sender: Any) {
objects.insert(NSDate(), at: 0)
let indexPath = IndexPath(row: 0, section: 0)
tableView.insertRows(at: [indexPath], with: .automatic)
}
// MARK: - Segues
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
if let indexPath = tableView.indexPathForSelectedRow {
// let object = objects[indexPath.row] as! NSDate
let object = dreams[indexPath.row]
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
controller.detailItem = object
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
detailViewController = controller
}
}
}
// MARK: - Table View
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// return objects.count
return dreams.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
// let object = objects[indexPath.row] as! NSDate
// cell.textLabel!.text = object.description
let dream: Dream
dream = dreams[indexPath.row]
cell.textLabel!.text = dream.description
return cell
}
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
objects.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
}
extension MasterViewController {
fileprivate func setupNotificationObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(reloadTableView(_:)), name: .dataRetrieved, object: nil)
}
fileprivate func removeNotificationObserver() {
NotificationCenter.default.removeObserver(self, name: .dataRetrieved, object: nil)
}
@objc fileprivate func reloadTableView(_ notification: Notification) {
DispatchQueue.main.async { [unowned self] in
print("====",self.dreams)
self.tableView.reloadData()
}
}
var dreams : [Dream] {
return ApplicationData.DatabaseData.read()
}
}
//
// Dream.swift
// swift01
//
// Created by on 2020/8/19.
// Copyright © 2020 admin. All rights reserved.
//
import Foundation
struct Dream {
var title: String
var dateString: String
var tags: [String]
var description: String
}
//
// DreamData.swift
// swift01
//
// Created by on 2020/8/19.
// Copyright © 2020 admin. All rights reserved.
//
import Foundation
struct DreamData {
var data = [Dream]()
}
extension DreamData {
func write(toData data: Dream) {
ApplicationData.DatabaseData.data.append(data)
}
func read() -> [Dream] {
return ApplicationData.DatabaseData.data
}
}
class ApplicationData {
static var DatabaseData = DreamData()
}
//
// NotificationName_Ext.swift
// swift01
//
// Created by on 2020/8/19.
// Copyright © 2020 admin. All rights reserved.
//
import Foundation
extension Notification.Name {
static let dataRetrieved = Notification.Name("dataRetrieved")
}
//
// Resource.swift
// swift01
//
// Created by on 2020/8/18.
// Copyright © 2020 admin. All rights reserved.
//
import Foundation
struct Resource<T> {
let url: URL
let parse: (Data) -> T?
}
extension Resource where T: Decodable {
init(_ url: URL, parseJSON: @escaping (Data) -> T?) {
self.url = url
// self.parse = { data in
// let decoder = JSONDecoder()
// let object = try? decoder.decode(T.self, from: data)
// return object
// }
self.parse = parseJSON
}
}
//
// SceneDelegate.swift
// swift01
//
// Created by on 2020/8/18.
// Copyright © 2020 admin. All rights reserved.
//
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate, UISplitViewControllerDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let window = window else { return }
guard let splitViewController = window.rootViewController as? UISplitViewController else { return }
guard let navigationController = splitViewController.viewControllers.last as? UINavigationController else { return }
navigationController.topViewController?.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
navigationController.topViewController?.navigationItem.leftItemsSupplementBackButton = true
splitViewController.delegate = self
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
// MARK: - Split view
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false }
guard let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController else { return false }
if topAsDetailController.detailItem == nil {
// Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
return true
}
return false
}
}
//
// DateFmt.swift
// swift01
//
// Created by on 2020/8/18.
// Copyright © 2020 admin. All rights reserved.
//
import Foundation
struct DateFmt {
let dateString: String
init(date: Date) {
let formatter = DateFormatter()
formatter.dateFormat = "d MMM yyyy"
dateString = formatter.string(from: date)
}
}
//
// RandomNumberGenerator.swift
// swift01
//
// Created by on 2020/8/19.
// Copyright © 2020 admin. All rights reserved.
//
import Foundation
import GameplayKit
struct RandomNumberGenerator {
fileprivate let source = GKRandomSource.sharedRandom()
public func getRandomNumber(withUpperBound bound: Int) -> Double {
let randomSource = source.nextInt(upperBound: bound)
return Double(randomSource)
}
}
//
// WebService.swift
// swift01
//
// Created by on 2020/8/19.
// Copyright © 2020 admin. All rights reserved.
//
import Foundation
final class WebService {
func load<T>(resource: Resource<T>, completion:@escaping(T?)->Void) {
URLSession.shared.dataTask(with: resource.url) {
(receivedData, _, error) in
if let error = error {
print(error.localizedDescription)
return;
}
guard let data = receivedData else {return completion(nil)}
completion(resource.parse(data))
}.resume()
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册