mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-03-26 11:21:24 +01:00
Add examples project
This commit is contained in:
21
Examples/Combine using GitHub API/.gitignore
vendored
Executable file
21
Examples/Combine using GitHub API/.gitignore
vendored
Executable file
@@ -0,0 +1,21 @@
|
||||
.DS_Store
|
||||
*/build/*
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata
|
||||
profile
|
||||
*.moved-aside
|
||||
DerivedData
|
||||
.idea/
|
||||
*.hmap
|
||||
*.xccheckout
|
||||
*.xcuserstate
|
||||
xcuserdata/
|
||||
*.moved-aside
|
||||
*.xcuserstate
|
||||
22
Examples/Combine using GitHub API/LICENSE
Executable file
22
Examples/Combine using GitHub API/LICENSE
Executable file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 ra1028
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
19
Examples/Combine using GitHub API/README.md
Executable file
19
Examples/Combine using GitHub API/README.md
Executable file
@@ -0,0 +1,19 @@
|
||||
# SwiftUI-Combine-Example
|
||||
This is an example project of [SwiftUI](https://developer.apple.com/xcode/swiftui) and [Combine](https://developer.apple.com/documentation/combine) using GitHub `GET /search/users` API.
|
||||
|
||||
<p align="center">
|
||||
<img src="./assets/sample.png" width="250">
|
||||
</p>
|
||||
|
||||
## :clipboard: Requirements
|
||||
- Swift5.1 Beta
|
||||
- Xcode11.0 Beta
|
||||
- iOS 13.0 Beta
|
||||
|
||||
## :warning: GitHub API Rate Limiting
|
||||
GitHub search API has a [rate limit rules](https://developer.github.com/v3/search/#rate-limit).
|
||||
For unauthenticated requests, the rate limit allows you to make up to 10 requests per minute.
|
||||
|
||||
## :books: Credit
|
||||
- [Official SwiftUI Tutorial](https://developer.apple.com/tutorials/swiftui)
|
||||
- [Combine Apple Developer Document](https://developer.apple.com/documentation/combine)
|
||||
@@ -0,0 +1,373 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 50;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
6B194EFF22A6BA07001B3151 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194EFE22A6BA07001B3151 /* AppDelegate.swift */; };
|
||||
6B194F0122A6BA07001B3151 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F0022A6BA07001B3151 /* SceneDelegate.swift */; };
|
||||
6B194F0322A6BA07001B3151 /* SearchUserView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F0222A6BA07001B3151 /* SearchUserView.swift */; };
|
||||
6B194F0522A6BA08001B3151 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6B194F0422A6BA08001B3151 /* Assets.xcassets */; };
|
||||
6B194F0822A6BA08001B3151 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6B194F0722A6BA08001B3151 /* Preview Assets.xcassets */; };
|
||||
6B194F0B22A6BA08001B3151 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6B194F0922A6BA08001B3151 /* LaunchScreen.storyboard */; };
|
||||
6B194F1322A7108C001B3151 /* SearchUserRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1222A7108C001B3151 /* SearchUserRow.swift */; };
|
||||
6B194F1522A710AB001B3151 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1422A710AB001B3151 /* User.swift */; };
|
||||
6B194F1722A710E6001B3151 /* SearchUserResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1622A710E6001B3151 /* SearchUserResponse.swift */; };
|
||||
6B194F1922A710FF001B3151 /* SearchUserViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1822A710FF001B3151 /* SearchUserViewModel.swift */; };
|
||||
6B194F1B22A7112D001B3151 /* SearchUserBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1A22A7112D001B3151 /* SearchUserBar.swift */; };
|
||||
6B194F1D22A71154001B3151 /* FoundationExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1C22A71154001B3151 /* FoundationExtensions.swift */; };
|
||||
6B194F1F22A71B0F001B3151 /* AnySubscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1E22A71B0F001B3151 /* AnySubscription.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
6B194EFB22A6BA07001B3151 /* SwiftUI-Combine-Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SwiftUI-Combine-Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
6B194EFE22A6BA07001B3151 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
6B194F0022A6BA07001B3151 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
|
||||
6B194F0222A6BA07001B3151 /* SearchUserView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchUserView.swift; sourceTree = "<group>"; };
|
||||
6B194F0422A6BA08001B3151 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
6B194F0722A6BA08001B3151 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
||||
6B194F0A22A6BA08001B3151 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
6B194F0C22A6BA08001B3151 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
6B194F1222A7108C001B3151 /* SearchUserRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchUserRow.swift; sourceTree = "<group>"; };
|
||||
6B194F1422A710AB001B3151 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
|
||||
6B194F1622A710E6001B3151 /* SearchUserResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchUserResponse.swift; sourceTree = "<group>"; };
|
||||
6B194F1822A710FF001B3151 /* SearchUserViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchUserViewModel.swift; sourceTree = "<group>"; };
|
||||
6B194F1A22A7112D001B3151 /* SearchUserBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchUserBar.swift; sourceTree = "<group>"; };
|
||||
6B194F1C22A71154001B3151 /* FoundationExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoundationExtensions.swift; sourceTree = "<group>"; };
|
||||
6B194F1E22A71B0F001B3151 /* AnySubscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnySubscription.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
6B194EF822A6BA07001B3151 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
6B194EF222A6BA07001B3151 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6B194EFD22A6BA07001B3151 /* SwiftUI-Combine-Example */,
|
||||
6B194EFC22A6BA07001B3151 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
6B194EFC22A6BA07001B3151 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6B194EFB22A6BA07001B3151 /* SwiftUI-Combine-Example.app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
6B194EFD22A6BA07001B3151 /* SwiftUI-Combine-Example */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6B194F0222A6BA07001B3151 /* SearchUserView.swift */,
|
||||
6B194F1822A710FF001B3151 /* SearchUserViewModel.swift */,
|
||||
6B194F1A22A7112D001B3151 /* SearchUserBar.swift */,
|
||||
6B194F1222A7108C001B3151 /* SearchUserRow.swift */,
|
||||
6B194F1622A710E6001B3151 /* SearchUserResponse.swift */,
|
||||
6B194F1422A710AB001B3151 /* User.swift */,
|
||||
6B194F1E22A71B0F001B3151 /* AnySubscription.swift */,
|
||||
6B194F1C22A71154001B3151 /* FoundationExtensions.swift */,
|
||||
6B194F0022A6BA07001B3151 /* SceneDelegate.swift */,
|
||||
6B194EFE22A6BA07001B3151 /* AppDelegate.swift */,
|
||||
6B194F0422A6BA08001B3151 /* Assets.xcassets */,
|
||||
6B194F0922A6BA08001B3151 /* LaunchScreen.storyboard */,
|
||||
6B194F0C22A6BA08001B3151 /* Info.plist */,
|
||||
6B194F0622A6BA08001B3151 /* Preview Content */,
|
||||
);
|
||||
path = "SwiftUI-Combine-Example";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
6B194F0622A6BA08001B3151 /* Preview Content */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6B194F0722A6BA08001B3151 /* Preview Assets.xcassets */,
|
||||
);
|
||||
path = "Preview Content";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
6B194EFA22A6BA07001B3151 /* SwiftUI-Combine-Example */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 6B194F0F22A6BA08001B3151 /* Build configuration list for PBXNativeTarget "SwiftUI-Combine-Example" */;
|
||||
buildPhases = (
|
||||
6B194EF722A6BA07001B3151 /* Sources */,
|
||||
6B194EF822A6BA07001B3151 /* Frameworks */,
|
||||
6B194EF922A6BA07001B3151 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = "SwiftUI-Combine-Example";
|
||||
productName = "SwiftUI-Combine-Example";
|
||||
productReference = 6B194EFB22A6BA07001B3151 /* SwiftUI-Combine-Example.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
6B194EF322A6BA07001B3151 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 1100;
|
||||
LastUpgradeCheck = 1100;
|
||||
ORGANIZATIONNAME = "Ryo Aoyama";
|
||||
TargetAttributes = {
|
||||
6B194EFA22A6BA07001B3151 = {
|
||||
CreatedOnToolsVersion = 11.0;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 6B194EF622A6BA07001B3151 /* Build configuration list for PBXProject "SwiftUI-Combine-Example" */;
|
||||
compatibilityVersion = "Xcode 9.3";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = 6B194EF222A6BA07001B3151;
|
||||
productRefGroup = 6B194EFC22A6BA07001B3151 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
6B194EFA22A6BA07001B3151 /* SwiftUI-Combine-Example */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
6B194EF922A6BA07001B3151 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
6B194F0B22A6BA08001B3151 /* LaunchScreen.storyboard in Resources */,
|
||||
6B194F0822A6BA08001B3151 /* Preview Assets.xcassets in Resources */,
|
||||
6B194F0522A6BA08001B3151 /* Assets.xcassets in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
6B194EF722A6BA07001B3151 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
6B194F1B22A7112D001B3151 /* SearchUserBar.swift in Sources */,
|
||||
6B194EFF22A6BA07001B3151 /* AppDelegate.swift in Sources */,
|
||||
6B194F0122A6BA07001B3151 /* SceneDelegate.swift in Sources */,
|
||||
6B194F1F22A71B0F001B3151 /* AnySubscription.swift in Sources */,
|
||||
6B194F0322A6BA07001B3151 /* SearchUserView.swift in Sources */,
|
||||
6B194F1922A710FF001B3151 /* SearchUserViewModel.swift in Sources */,
|
||||
6B194F1722A710E6001B3151 /* SearchUserResponse.swift in Sources */,
|
||||
6B194F1D22A71154001B3151 /* FoundationExtensions.swift in Sources */,
|
||||
6B194F1522A710AB001B3151 /* User.swift in Sources */,
|
||||
6B194F1322A7108C001B3151 /* SearchUserRow.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
6B194F0922A6BA08001B3151 /* LaunchScreen.storyboard */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
6B194F0A22A6BA08001B3151 /* Base */,
|
||||
);
|
||||
name = LaunchScreen.storyboard;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
6B194F0D22A6BA08001B3151 /* 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.0;
|
||||
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;
|
||||
};
|
||||
6B194F0E22A6BA08001B3151 /* 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.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_COMPILATION_MODE = wholemodule;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
6B194F1022A6BA08001B3151 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_ASSET_PATHS = "SwiftUI-Combine-Example/Preview\\ Content";
|
||||
ENABLE_PREVIEWS = YES;
|
||||
INFOPLIST_FILE = "SwiftUI-Combine-Example/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.ryo.SwiftUI-Combine-Example";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = 1;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
6B194F1122A6BA08001B3151 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_ASSET_PATHS = "SwiftUI-Combine-Example/Preview\\ Content";
|
||||
ENABLE_PREVIEWS = YES;
|
||||
INFOPLIST_FILE = "SwiftUI-Combine-Example/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.ryo.SwiftUI-Combine-Example";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = 1;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
6B194EF622A6BA07001B3151 /* Build configuration list for PBXProject "SwiftUI-Combine-Example" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
6B194F0D22A6BA08001B3151 /* Debug */,
|
||||
6B194F0E22A6BA08001B3151 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
6B194F0F22A6BA08001B3151 /* Build configuration list for PBXNativeTarget "SwiftUI-Combine-Example" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
6B194F1022A6BA08001B3151 /* Debug */,
|
||||
6B194F1122A6BA08001B3151 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 6B194EF322A6BA07001B3151 /* Project object */;
|
||||
}
|
||||
7
Examples/Combine using GitHub API/SwiftUI-Combine-Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Executable file
7
Examples/Combine using GitHub API/SwiftUI-Combine-Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Executable file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:SwiftUI-Combine-Example.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,15 @@
|
||||
import Combine
|
||||
|
||||
final class AnySubscription: Subscription {
|
||||
private let cancellable: Cancellable
|
||||
|
||||
init(_ cancel: @escaping () -> Void) {
|
||||
cancellable = AnyCancellable(cancel)
|
||||
}
|
||||
|
||||
func request(_ demand: Subscribers.Demand) {}
|
||||
|
||||
func cancel() {
|
||||
cancellable.cancel()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import UIKit
|
||||
|
||||
@UIApplicationMain
|
||||
final class AppDelegate: UIResponder, UIApplicationDelegate {}
|
||||
@@ -0,0 +1,98 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "20x20",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "20x20",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "20x20",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "20x20",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "29x29",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "29x29",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "40x40",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "40x40",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "76x76",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "76x76",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "83.5x83.5",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ios-marketing",
|
||||
"size" : "1024x1024",
|
||||
"scale" : "1x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,34 @@
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
enum RequestError: Error {
|
||||
case request(code: Int, error: Error?)
|
||||
case unknown
|
||||
}
|
||||
|
||||
extension URLSession {
|
||||
func send(request: URLRequest) -> AnyPublisher<(data: Data, response: HTTPURLResponse), RequestError> {
|
||||
AnyPublisher<(data: Data, response: HTTPURLResponse), RequestError> { subscriber in
|
||||
let task = self.dataTask(with: request) { data, response, error in
|
||||
DispatchQueue.main.async {
|
||||
let httpReponse = response as? HTTPURLResponse
|
||||
if let data = data, let httpReponse = httpReponse, 200..<300 ~= httpReponse.statusCode {
|
||||
_ = subscriber.receive((data, httpReponse))
|
||||
subscriber.receive(completion: .finished)
|
||||
}
|
||||
else if let httpReponse = httpReponse {
|
||||
subscriber.receive(completion: .failure(.request(code: httpReponse.statusCode, error: error)))
|
||||
}
|
||||
else {
|
||||
subscriber.receive(completion: .failure(.unknown))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subscriber.receive(subscription: AnySubscription(task.cancel))
|
||||
task.resume()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONDecoder: TopLevelDecoder {}
|
||||
60
Examples/Combine using GitHub API/SwiftUI-Combine-Example/Info.plist
Executable file
60
Examples/Combine using GitHub API/SwiftUI-Combine-Example/Info.plist
Executable file
@@ -0,0 +1,60 @@
|
||||
<?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>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UISceneConfigurationName</key>
|
||||
<string>Default Configuration</string>
|
||||
<key>UISceneDelegateClassName</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
|
||||
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
var window: UIWindow?
|
||||
|
||||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
||||
let window = UIWindow(frame: UIScreen.main.bounds)
|
||||
window.rootViewController = UIHostingController(
|
||||
rootView: SearchUserView().environmentObject(SearchUserViewModel())
|
||||
)
|
||||
self.window = window
|
||||
window.makeKeyAndVisible()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SearchUserBar: View {
|
||||
@Binding var text: String
|
||||
@State var action: () -> Void
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
HStack {
|
||||
TextField(
|
||||
$text,
|
||||
placeholder: Text("Search User")
|
||||
.color(Color.gray)
|
||||
)
|
||||
.padding([.leading, .trailing], 8)
|
||||
.frame(height: 32)
|
||||
.background(Color.white.opacity(0.4))
|
||||
.cornerRadius(8)
|
||||
|
||||
Button(
|
||||
action: action,
|
||||
label: { Text("Search") }
|
||||
)
|
||||
.foregroundColor(Color.white)
|
||||
}
|
||||
.padding([.leading, .trailing], 16)
|
||||
}
|
||||
.frame(height: 64)
|
||||
.background(Color.yellow)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
struct SearchUserResponse: Decodable {
|
||||
var items: [User]
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SearchUserRow: View {
|
||||
@EnvironmentObject var viewModel: SearchUserViewModel
|
||||
@State var user: User
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
self.viewModel.userImages[user].map { image in
|
||||
Image(uiImage: image)
|
||||
.frame(width: 44, height: 44)
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.clipShape(Circle())
|
||||
.overlay(Circle().stroke(Color.gray, lineWidth: 1))
|
||||
}
|
||||
|
||||
Text(user.login)
|
||||
.font(Font.system(size: 18).bold())
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
|
||||
.frame(height: 60)
|
||||
.onAppear { self.viewModel.getImage(for: self.user) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SearchUserView: View {
|
||||
@EnvironmentObject var viewModel: SearchUserViewModel
|
||||
@State var text = "ra1028"
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
VStack {
|
||||
SearchUserBar(text: $text) {
|
||||
self.viewModel.search(name: self.text)
|
||||
}
|
||||
|
||||
List(viewModel.users) { user in
|
||||
SearchUserRow(user: user)
|
||||
.tapAction { print(user) }
|
||||
}
|
||||
}
|
||||
.navigationBarTitle(Text("Users"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
final class SearchUserViewModel: BindableObject {
|
||||
var didChange = PassthroughSubject<SearchUserViewModel, Never>()
|
||||
|
||||
private(set) var users = [User]() {
|
||||
didSet {
|
||||
didChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
private(set) var userImages = [User: UIImage]() {
|
||||
didSet {
|
||||
didChange.send(self)
|
||||
}
|
||||
}
|
||||
|
||||
private var cancellable: Cancellable? {
|
||||
didSet { oldValue?.cancel() }
|
||||
}
|
||||
|
||||
func search(name: String) {
|
||||
guard !name.isEmpty else {
|
||||
return users = []
|
||||
}
|
||||
|
||||
var urlComponents = URLComponents(string: "https://api.github.com/search/users")!
|
||||
urlComponents.queryItems = [
|
||||
URLQueryItem(name: "q", value: name)
|
||||
]
|
||||
var request = URLRequest(url: urlComponents.url!)
|
||||
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
let assign = Subscribers.Assign(object: self, keyPath: \.users)
|
||||
cancellable = assign
|
||||
|
||||
URLSession.shared.send(request: request)
|
||||
.map { $0.data }
|
||||
.decode(type: SearchUserResponse.self, decoder: JSONDecoder())
|
||||
.map { $0.items }
|
||||
.replaceError(with: [])
|
||||
.receive(subscriber: assign)
|
||||
}
|
||||
|
||||
func getImage(for user: User) {
|
||||
guard case .none = userImages[user] else {
|
||||
return
|
||||
}
|
||||
|
||||
let request = URLRequest(url: user.avatar_url)
|
||||
URLSession.shared.send(request: request)
|
||||
.map { UIImage(data: $0.data) }
|
||||
.replaceError(with: nil)
|
||||
.eraseToAnyPublisher()
|
||||
.receive(subscriber: Subscribers.Sink<AnyPublisher<UIImage?, Never>> { [weak self] image in
|
||||
self?.userImages[user] = image
|
||||
})
|
||||
}
|
||||
}
|
||||
8
Examples/Combine using GitHub API/SwiftUI-Combine-Example/User.swift
Executable file
8
Examples/Combine using GitHub API/SwiftUI-Combine-Example/User.swift
Executable file
@@ -0,0 +1,8 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct User: Hashable, Identifiable, Decodable {
|
||||
var id: Int64
|
||||
var login: String
|
||||
var avatar_url: URL
|
||||
}
|
||||
BIN
Examples/Combine using GitHub API/assets/sample.png
Executable file
BIN
Examples/Combine using GitHub API/assets/sample.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 299 KiB |
Reference in New Issue
Block a user