├── .github └── FUNDING.yml ├── .gitignore ├── .swift-version ├── Demo ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── LICENSE ├── Once.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── Once.xcscheme ├── Once ├── Info.plist ├── Once.h └── Once.swift ├── Package.swift └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: sgr-ksmt 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 3.0.2 2 | -------------------------------------------------------------------------------- /Demo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Demo 4 | // 5 | // Created by Suguru Kishimoto on 9/25/16. 6 | // Copyright © 2016 Suguru Kishimoto. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Demo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Demo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Demo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Demo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Demo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Demo 4 | // 5 | // Created by Suguru Kishimoto on 9/25/16. 6 | // Copyright © 2016 Suguru Kishimoto. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Once 11 | 12 | class ViewController: UIViewController { 13 | 14 | @IBOutlet private weak var button: UIButton! 15 | 16 | lazy var buttonFirstTap: OnceClosure = Once.execute { 17 | print("[First] tapped!!") 18 | } 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | } 22 | 23 | override func didReceiveMemoryWarning() { 24 | super.didReceiveMemoryWarning() 25 | } 26 | 27 | @IBAction func buttonDidTap() { 28 | buttonFirstTap?() 29 | print("tapped!!") 30 | } 31 | 32 | } 33 | 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Suguru Kishimoto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Once.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4D4DE4E41D96D72D00CC2535 /* Once.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D4DE4E31D96D72D00CC2535 /* Once.swift */; }; 11 | 4D4DE4EC1D96D76700CC2535 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D4DE4EB1D96D76700CC2535 /* AppDelegate.swift */; }; 12 | 4D4DE4EE1D96D76700CC2535 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D4DE4ED1D96D76700CC2535 /* ViewController.swift */; }; 13 | 4D4DE4F11D96D76700CC2535 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4D4DE4EF1D96D76700CC2535 /* Main.storyboard */; }; 14 | 4D4DE4F31D96D76700CC2535 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4D4DE4F21D96D76700CC2535 /* Assets.xcassets */; }; 15 | 4D4DE4F61D96D76700CC2535 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4D4DE4F41D96D76700CC2535 /* LaunchScreen.storyboard */; }; 16 | 4D4DE4FB1D96D77B00CC2535 /* Once.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DB127311D96D6EF006D8A49 /* Once.framework */; }; 17 | 4D4DE4FC1D96D77B00CC2535 /* Once.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4DB127311D96D6EF006D8A49 /* Once.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 18 | 4DB127361D96D6EF006D8A49 /* Once.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DB127341D96D6EF006D8A49 /* Once.h */; settings = {ATTRIBUTES = (Public, ); }; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 4D4DE4FD1D96D77B00CC2535 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 4DB127281D96D6EF006D8A49 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 4DB127301D96D6EF006D8A49; 27 | remoteInfo = Once; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXCopyFilesBuildPhase section */ 32 | 4D4DE4FF1D96D77B00CC2535 /* Embed Frameworks */ = { 33 | isa = PBXCopyFilesBuildPhase; 34 | buildActionMask = 2147483647; 35 | dstPath = ""; 36 | dstSubfolderSpec = 10; 37 | files = ( 38 | 4D4DE4FC1D96D77B00CC2535 /* Once.framework in Embed Frameworks */, 39 | ); 40 | name = "Embed Frameworks"; 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXCopyFilesBuildPhase section */ 44 | 45 | /* Begin PBXFileReference section */ 46 | 4D4DE4E31D96D72D00CC2535 /* Once.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Once.swift; sourceTree = ""; }; 47 | 4D4DE4E91D96D76700CC2535 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | 4D4DE4EB1D96D76700CC2535 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 49 | 4D4DE4ED1D96D76700CC2535 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 50 | 4D4DE4F01D96D76700CC2535 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 51 | 4D4DE4F21D96D76700CC2535 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 52 | 4D4DE4F51D96D76700CC2535 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 53 | 4D4DE4F71D96D76700CC2535 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | 4DB127311D96D6EF006D8A49 /* Once.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Once.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | 4DB127341D96D6EF006D8A49 /* Once.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Once.h; sourceTree = ""; }; 56 | 4DB127351D96D6EF006D8A49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | /* End PBXFileReference section */ 58 | 59 | /* Begin PBXFrameworksBuildPhase section */ 60 | 4D4DE4E61D96D76700CC2535 /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | 4D4DE4FB1D96D77B00CC2535 /* Once.framework in Frameworks */, 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | 4DB1272D1D96D6EF006D8A49 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | /* End PBXFrameworksBuildPhase section */ 76 | 77 | /* Begin PBXGroup section */ 78 | 4D4DE4EA1D96D76700CC2535 /* Demo */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 4D4DE4EB1D96D76700CC2535 /* AppDelegate.swift */, 82 | 4D4DE4ED1D96D76700CC2535 /* ViewController.swift */, 83 | 4D4DE4EF1D96D76700CC2535 /* Main.storyboard */, 84 | 4D4DE4F21D96D76700CC2535 /* Assets.xcassets */, 85 | 4D4DE4F41D96D76700CC2535 /* LaunchScreen.storyboard */, 86 | 4D4DE4F71D96D76700CC2535 /* Info.plist */, 87 | ); 88 | path = Demo; 89 | sourceTree = ""; 90 | }; 91 | 4DB127271D96D6EF006D8A49 = { 92 | isa = PBXGroup; 93 | children = ( 94 | 4DB127331D96D6EF006D8A49 /* Once */, 95 | 4D4DE4EA1D96D76700CC2535 /* Demo */, 96 | 4DB127321D96D6EF006D8A49 /* Products */, 97 | ); 98 | sourceTree = ""; 99 | }; 100 | 4DB127321D96D6EF006D8A49 /* Products */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | 4DB127311D96D6EF006D8A49 /* Once.framework */, 104 | 4D4DE4E91D96D76700CC2535 /* Demo.app */, 105 | ); 106 | name = Products; 107 | sourceTree = ""; 108 | }; 109 | 4DB127331D96D6EF006D8A49 /* Once */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 4DB127341D96D6EF006D8A49 /* Once.h */, 113 | 4DB127351D96D6EF006D8A49 /* Info.plist */, 114 | 4D4DE4E31D96D72D00CC2535 /* Once.swift */, 115 | ); 116 | path = Once; 117 | sourceTree = ""; 118 | }; 119 | /* End PBXGroup section */ 120 | 121 | /* Begin PBXHeadersBuildPhase section */ 122 | 4DB1272E1D96D6EF006D8A49 /* Headers */ = { 123 | isa = PBXHeadersBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | 4DB127361D96D6EF006D8A49 /* Once.h in Headers */, 127 | ); 128 | runOnlyForDeploymentPostprocessing = 0; 129 | }; 130 | /* End PBXHeadersBuildPhase section */ 131 | 132 | /* Begin PBXNativeTarget section */ 133 | 4D4DE4E81D96D76700CC2535 /* Demo */ = { 134 | isa = PBXNativeTarget; 135 | buildConfigurationList = 4D4DE4F81D96D76700CC2535 /* Build configuration list for PBXNativeTarget "Demo" */; 136 | buildPhases = ( 137 | 4D4DE4E51D96D76700CC2535 /* Sources */, 138 | 4D4DE4E61D96D76700CC2535 /* Frameworks */, 139 | 4D4DE4E71D96D76700CC2535 /* Resources */, 140 | 4D4DE4FF1D96D77B00CC2535 /* Embed Frameworks */, 141 | ); 142 | buildRules = ( 143 | ); 144 | dependencies = ( 145 | 4D4DE4FE1D96D77B00CC2535 /* PBXTargetDependency */, 146 | ); 147 | name = Demo; 148 | productName = Demo; 149 | productReference = 4D4DE4E91D96D76700CC2535 /* Demo.app */; 150 | productType = "com.apple.product-type.application"; 151 | }; 152 | 4DB127301D96D6EF006D8A49 /* Once */ = { 153 | isa = PBXNativeTarget; 154 | buildConfigurationList = 4DB127391D96D6EF006D8A49 /* Build configuration list for PBXNativeTarget "Once" */; 155 | buildPhases = ( 156 | 4DB1272C1D96D6EF006D8A49 /* Sources */, 157 | 4DB1272D1D96D6EF006D8A49 /* Frameworks */, 158 | 4DB1272E1D96D6EF006D8A49 /* Headers */, 159 | 4DB1272F1D96D6EF006D8A49 /* Resources */, 160 | ); 161 | buildRules = ( 162 | ); 163 | dependencies = ( 164 | ); 165 | name = Once; 166 | productName = Once; 167 | productReference = 4DB127311D96D6EF006D8A49 /* Once.framework */; 168 | productType = "com.apple.product-type.framework"; 169 | }; 170 | /* End PBXNativeTarget section */ 171 | 172 | /* Begin PBXProject section */ 173 | 4DB127281D96D6EF006D8A49 /* Project object */ = { 174 | isa = PBXProject; 175 | attributes = { 176 | LastSwiftUpdateCheck = 0800; 177 | LastUpgradeCheck = 0800; 178 | ORGANIZATIONNAME = "Suguru Kishimoto"; 179 | TargetAttributes = { 180 | 4D4DE4E81D96D76700CC2535 = { 181 | CreatedOnToolsVersion = 8.0; 182 | DevelopmentTeam = KW3G83N6K6; 183 | ProvisioningStyle = Automatic; 184 | }; 185 | 4DB127301D96D6EF006D8A49 = { 186 | CreatedOnToolsVersion = 8.0; 187 | DevelopmentTeam = KW3G83N6K6; 188 | LastSwiftMigration = 0800; 189 | ProvisioningStyle = Automatic; 190 | }; 191 | }; 192 | }; 193 | buildConfigurationList = 4DB1272B1D96D6EF006D8A49 /* Build configuration list for PBXProject "Once" */; 194 | compatibilityVersion = "Xcode 3.2"; 195 | developmentRegion = English; 196 | hasScannedForEncodings = 0; 197 | knownRegions = ( 198 | en, 199 | Base, 200 | ); 201 | mainGroup = 4DB127271D96D6EF006D8A49; 202 | productRefGroup = 4DB127321D96D6EF006D8A49 /* Products */; 203 | projectDirPath = ""; 204 | projectRoot = ""; 205 | targets = ( 206 | 4DB127301D96D6EF006D8A49 /* Once */, 207 | 4D4DE4E81D96D76700CC2535 /* Demo */, 208 | ); 209 | }; 210 | /* End PBXProject section */ 211 | 212 | /* Begin PBXResourcesBuildPhase section */ 213 | 4D4DE4E71D96D76700CC2535 /* Resources */ = { 214 | isa = PBXResourcesBuildPhase; 215 | buildActionMask = 2147483647; 216 | files = ( 217 | 4D4DE4F61D96D76700CC2535 /* LaunchScreen.storyboard in Resources */, 218 | 4D4DE4F31D96D76700CC2535 /* Assets.xcassets in Resources */, 219 | 4D4DE4F11D96D76700CC2535 /* Main.storyboard in Resources */, 220 | ); 221 | runOnlyForDeploymentPostprocessing = 0; 222 | }; 223 | 4DB1272F1D96D6EF006D8A49 /* Resources */ = { 224 | isa = PBXResourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | ); 228 | runOnlyForDeploymentPostprocessing = 0; 229 | }; 230 | /* End PBXResourcesBuildPhase section */ 231 | 232 | /* Begin PBXSourcesBuildPhase section */ 233 | 4D4DE4E51D96D76700CC2535 /* Sources */ = { 234 | isa = PBXSourcesBuildPhase; 235 | buildActionMask = 2147483647; 236 | files = ( 237 | 4D4DE4EE1D96D76700CC2535 /* ViewController.swift in Sources */, 238 | 4D4DE4EC1D96D76700CC2535 /* AppDelegate.swift in Sources */, 239 | ); 240 | runOnlyForDeploymentPostprocessing = 0; 241 | }; 242 | 4DB1272C1D96D6EF006D8A49 /* Sources */ = { 243 | isa = PBXSourcesBuildPhase; 244 | buildActionMask = 2147483647; 245 | files = ( 246 | 4D4DE4E41D96D72D00CC2535 /* Once.swift in Sources */, 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | }; 250 | /* End PBXSourcesBuildPhase section */ 251 | 252 | /* Begin PBXTargetDependency section */ 253 | 4D4DE4FE1D96D77B00CC2535 /* PBXTargetDependency */ = { 254 | isa = PBXTargetDependency; 255 | target = 4DB127301D96D6EF006D8A49 /* Once */; 256 | targetProxy = 4D4DE4FD1D96D77B00CC2535 /* PBXContainerItemProxy */; 257 | }; 258 | /* End PBXTargetDependency section */ 259 | 260 | /* Begin PBXVariantGroup section */ 261 | 4D4DE4EF1D96D76700CC2535 /* Main.storyboard */ = { 262 | isa = PBXVariantGroup; 263 | children = ( 264 | 4D4DE4F01D96D76700CC2535 /* Base */, 265 | ); 266 | name = Main.storyboard; 267 | sourceTree = ""; 268 | }; 269 | 4D4DE4F41D96D76700CC2535 /* LaunchScreen.storyboard */ = { 270 | isa = PBXVariantGroup; 271 | children = ( 272 | 4D4DE4F51D96D76700CC2535 /* Base */, 273 | ); 274 | name = LaunchScreen.storyboard; 275 | sourceTree = ""; 276 | }; 277 | /* End PBXVariantGroup section */ 278 | 279 | /* Begin XCBuildConfiguration section */ 280 | 4D4DE4F91D96D76700CC2535 /* Debug */ = { 281 | isa = XCBuildConfiguration; 282 | buildSettings = { 283 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 285 | DEVELOPMENT_TEAM = KW3G83N6K6; 286 | INFOPLIST_FILE = Demo/Info.plist; 287 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 288 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 289 | PRODUCT_BUNDLE_IDENTIFIER = "-.Demo"; 290 | PRODUCT_NAME = "$(TARGET_NAME)"; 291 | SWIFT_VERSION = 3.0; 292 | }; 293 | name = Debug; 294 | }; 295 | 4D4DE4FA1D96D76700CC2535 /* Release */ = { 296 | isa = XCBuildConfiguration; 297 | buildSettings = { 298 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 299 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 300 | DEVELOPMENT_TEAM = KW3G83N6K6; 301 | INFOPLIST_FILE = Demo/Info.plist; 302 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 303 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 304 | PRODUCT_BUNDLE_IDENTIFIER = "-.Demo"; 305 | PRODUCT_NAME = "$(TARGET_NAME)"; 306 | SWIFT_VERSION = 3.0; 307 | }; 308 | name = Release; 309 | }; 310 | 4DB127371D96D6EF006D8A49 /* Debug */ = { 311 | isa = XCBuildConfiguration; 312 | buildSettings = { 313 | ALWAYS_SEARCH_USER_PATHS = NO; 314 | CLANG_ANALYZER_NONNULL = YES; 315 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 316 | CLANG_CXX_LIBRARY = "libc++"; 317 | CLANG_ENABLE_MODULES = YES; 318 | CLANG_ENABLE_OBJC_ARC = YES; 319 | CLANG_WARN_BOOL_CONVERSION = YES; 320 | CLANG_WARN_CONSTANT_CONVERSION = YES; 321 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 322 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 323 | CLANG_WARN_EMPTY_BODY = YES; 324 | CLANG_WARN_ENUM_CONVERSION = YES; 325 | CLANG_WARN_INFINITE_RECURSION = YES; 326 | CLANG_WARN_INT_CONVERSION = YES; 327 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 328 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 329 | CLANG_WARN_UNREACHABLE_CODE = YES; 330 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 331 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 332 | COPY_PHASE_STRIP = NO; 333 | CURRENT_PROJECT_VERSION = 1; 334 | DEBUG_INFORMATION_FORMAT = dwarf; 335 | ENABLE_STRICT_OBJC_MSGSEND = YES; 336 | ENABLE_TESTABILITY = YES; 337 | GCC_C_LANGUAGE_STANDARD = gnu99; 338 | GCC_DYNAMIC_NO_PIC = NO; 339 | GCC_NO_COMMON_BLOCKS = YES; 340 | GCC_OPTIMIZATION_LEVEL = 0; 341 | GCC_PREPROCESSOR_DEFINITIONS = ( 342 | "DEBUG=1", 343 | "$(inherited)", 344 | ); 345 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 346 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 347 | GCC_WARN_UNDECLARED_SELECTOR = YES; 348 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 349 | GCC_WARN_UNUSED_FUNCTION = YES; 350 | GCC_WARN_UNUSED_VARIABLE = YES; 351 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 352 | MTL_ENABLE_DEBUG_INFO = YES; 353 | ONLY_ACTIVE_ARCH = YES; 354 | SDKROOT = iphoneos; 355 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 356 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 357 | TARGETED_DEVICE_FAMILY = "1,2"; 358 | VERSIONING_SYSTEM = "apple-generic"; 359 | VERSION_INFO_PREFIX = ""; 360 | }; 361 | name = Debug; 362 | }; 363 | 4DB127381D96D6EF006D8A49 /* Release */ = { 364 | isa = XCBuildConfiguration; 365 | buildSettings = { 366 | ALWAYS_SEARCH_USER_PATHS = NO; 367 | CLANG_ANALYZER_NONNULL = YES; 368 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 369 | CLANG_CXX_LIBRARY = "libc++"; 370 | CLANG_ENABLE_MODULES = YES; 371 | CLANG_ENABLE_OBJC_ARC = YES; 372 | CLANG_WARN_BOOL_CONVERSION = YES; 373 | CLANG_WARN_CONSTANT_CONVERSION = YES; 374 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 375 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 376 | CLANG_WARN_EMPTY_BODY = YES; 377 | CLANG_WARN_ENUM_CONVERSION = YES; 378 | CLANG_WARN_INFINITE_RECURSION = YES; 379 | CLANG_WARN_INT_CONVERSION = YES; 380 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 381 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 382 | CLANG_WARN_UNREACHABLE_CODE = YES; 383 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 384 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 385 | COPY_PHASE_STRIP = NO; 386 | CURRENT_PROJECT_VERSION = 1; 387 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 388 | ENABLE_NS_ASSERTIONS = NO; 389 | ENABLE_STRICT_OBJC_MSGSEND = YES; 390 | GCC_C_LANGUAGE_STANDARD = gnu99; 391 | GCC_NO_COMMON_BLOCKS = YES; 392 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 393 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 394 | GCC_WARN_UNDECLARED_SELECTOR = YES; 395 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 396 | GCC_WARN_UNUSED_FUNCTION = YES; 397 | GCC_WARN_UNUSED_VARIABLE = YES; 398 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 399 | MTL_ENABLE_DEBUG_INFO = NO; 400 | SDKROOT = iphoneos; 401 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 402 | TARGETED_DEVICE_FAMILY = "1,2"; 403 | VALIDATE_PRODUCT = YES; 404 | VERSIONING_SYSTEM = "apple-generic"; 405 | VERSION_INFO_PREFIX = ""; 406 | }; 407 | name = Release; 408 | }; 409 | 4DB1273A1D96D6EF006D8A49 /* Debug */ = { 410 | isa = XCBuildConfiguration; 411 | buildSettings = { 412 | CLANG_ENABLE_MODULES = YES; 413 | CODE_SIGN_IDENTITY = ""; 414 | DEFINES_MODULE = YES; 415 | DEVELOPMENT_TEAM = KW3G83N6K6; 416 | DYLIB_COMPATIBILITY_VERSION = 1; 417 | DYLIB_CURRENT_VERSION = 1; 418 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 419 | INFOPLIST_FILE = Once/Info.plist; 420 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 421 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 422 | PRODUCT_BUNDLE_IDENTIFIER = "-.Once"; 423 | PRODUCT_NAME = "$(TARGET_NAME)"; 424 | SKIP_INSTALL = YES; 425 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 426 | SWIFT_VERSION = 3.0; 427 | }; 428 | name = Debug; 429 | }; 430 | 4DB1273B1D96D6EF006D8A49 /* Release */ = { 431 | isa = XCBuildConfiguration; 432 | buildSettings = { 433 | CLANG_ENABLE_MODULES = YES; 434 | CODE_SIGN_IDENTITY = ""; 435 | DEFINES_MODULE = YES; 436 | DEVELOPMENT_TEAM = KW3G83N6K6; 437 | DYLIB_COMPATIBILITY_VERSION = 1; 438 | DYLIB_CURRENT_VERSION = 1; 439 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 440 | INFOPLIST_FILE = Once/Info.plist; 441 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 442 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 443 | PRODUCT_BUNDLE_IDENTIFIER = "-.Once"; 444 | PRODUCT_NAME = "$(TARGET_NAME)"; 445 | SKIP_INSTALL = YES; 446 | SWIFT_VERSION = 3.0; 447 | }; 448 | name = Release; 449 | }; 450 | /* End XCBuildConfiguration section */ 451 | 452 | /* Begin XCConfigurationList section */ 453 | 4D4DE4F81D96D76700CC2535 /* Build configuration list for PBXNativeTarget "Demo" */ = { 454 | isa = XCConfigurationList; 455 | buildConfigurations = ( 456 | 4D4DE4F91D96D76700CC2535 /* Debug */, 457 | 4D4DE4FA1D96D76700CC2535 /* Release */, 458 | ); 459 | defaultConfigurationIsVisible = 0; 460 | }; 461 | 4DB1272B1D96D6EF006D8A49 /* Build configuration list for PBXProject "Once" */ = { 462 | isa = XCConfigurationList; 463 | buildConfigurations = ( 464 | 4DB127371D96D6EF006D8A49 /* Debug */, 465 | 4DB127381D96D6EF006D8A49 /* Release */, 466 | ); 467 | defaultConfigurationIsVisible = 0; 468 | defaultConfigurationName = Release; 469 | }; 470 | 4DB127391D96D6EF006D8A49 /* Build configuration list for PBXNativeTarget "Once" */ = { 471 | isa = XCConfigurationList; 472 | buildConfigurations = ( 473 | 4DB1273A1D96D6EF006D8A49 /* Debug */, 474 | 4DB1273B1D96D6EF006D8A49 /* Release */, 475 | ); 476 | defaultConfigurationIsVisible = 0; 477 | defaultConfigurationName = Release; 478 | }; 479 | /* End XCConfigurationList section */ 480 | }; 481 | rootObject = 4DB127281D96D6EF006D8A49 /* Project object */; 482 | } 483 | -------------------------------------------------------------------------------- /Once.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Once.xcodeproj/xcshareddata/xcschemes/Once.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Once/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Once/Once.h: -------------------------------------------------------------------------------- 1 | // 2 | // Once.h 3 | // Once 4 | // 5 | // Created by Suguru Kishimoto on 9/25/16. 6 | // Copyright © 2016 Suguru Kishimoto. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for Once. 12 | FOUNDATION_EXPORT double OnceVersionNumber; 13 | 14 | //! Project version string for Once. 15 | FOUNDATION_EXPORT const unsigned char OnceVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Once/Once.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Once.swift 3 | // Once 4 | // 5 | // Created by Suguru Kishimoto on 9/25/16. 6 | // Copyright © 2016 Suguru Kishimoto. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public typealias OnceClosure = (() -> Void)? 12 | 13 | public final class Once { 14 | private init() {} 15 | 16 | public static func execute(_ execute: () -> Void) -> OnceClosure { 17 | execute() 18 | return { return nil }() 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | import PackageDescription 2 | 3 | let package = Package(name: "Once") 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Once 2 | [![GitHub release](https://img.shields.io/github/release/sgr-ksmt/Once.svg)](https://github.com/sgr-ksmt/Once/releases) 3 | ![Language](https://img.shields.io/badge/language-Swift%203-orange.svg) 4 | [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 5 | [![Swift Package Manager](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager) 6 | 7 | Execute closure once!!! Once is a micro framework. 8 | 9 | ```swift 10 | import Once 11 | 12 | class ViewController: UIViewController { 13 | private var dataSource = DataSource() 14 | lazy var onceReloader: OnceClosure = execute_once { 15 | print("execute once") 16 | self.dataSource.reload() 17 | } 18 | 19 | override func viewWillAppear(_ animated: Bool) { 20 | super.viewWillAppear(animated) 21 | onceReloader?() 22 | } 23 | } 24 | ``` 25 | 26 | ### Legacy... 27 | 28 | ```swift 29 | class ViewController: UIViewController { 30 | private var dataSource = DataSource() 31 | private var callFirst = true 32 | 33 | override func viewWillAppear(_ animated: Bool) { 34 | super.viewWillAppear(animated) 35 | if callFirst { 36 | reloadOnce() 37 | callFirst = falee 38 | } 39 | } 40 | 41 | func reloadOnce() { 42 | print("execute once") 43 | self.dataSource.reload() 44 | } 45 | } 46 | ``` 47 | 48 | 49 | ## Features 50 | - Execute closure just once. 51 | - Don't need to have any flags that closure called or not. 52 | - This function doesn't capture any objects by using `no-escaped` closure. 53 | - You don't have to use `[weak self], [unowned self]`. 54 | - Micro library! 55 | 56 | 57 | ## How to use 58 | 59 | - 1. Import framework 60 | 61 | `import Once` 62 | 63 | - 2. Define `lazy var` instance. 64 | **Note**: Don't forget to write parameter: `OnceClosure` 65 | 66 | ```swift 67 | class ViewController: UIViewController { 68 | // as closure 69 | lazy var onceReloader: OnceClosure = execute_once { 70 | print("execute once") 71 | self.dataSource.reload() 72 | } 73 | 74 | // or function 75 | lazy var onceReloader2: OnceClosure = self.reloadOnce() 76 | 77 | func reloadOnce() -> OnceClosure { 78 | return execute_once { 79 | print("execute once") 80 | self.dataSource.reload() 81 | } 82 | } 83 | } 84 | ``` 85 | 86 | - 3. Execute once closure!! (need `?`) 87 | 88 | ```swift 89 | class ViewController: UIViewController { 90 | // ... 91 | override func viewWillAppear(_ animated: Bool) { 92 | super.viewWillAppear(animated) 93 | onceReloader?() 94 | } 95 | } 96 | ``` 97 | 98 | ### Caution 99 | Once-closure will not work anymore if it is assigned `nil` before executing. 100 | 101 | ```swift 102 | import Once 103 | 104 | class ViewController: UIViewController { 105 | private var dataSource = DataSource() 106 | lazy var onceReloader: OnceClosure = execute_once { 107 | print("execute once") 108 | self.dataSource.reload() 109 | } 110 | 111 | override func viewWillAppear(_ animated: Bool) { 112 | super.viewWillAppear(animated) 113 | onceReloader = nil 114 | onceReloader?() // doesn't work. 115 | } 116 | } 117 | ``` 118 | 119 | ## Requirements 120 | - iOS 8.0+ 121 | - Xcode 8+ 122 | - Swift 3 123 | 124 | ## Installation 125 | You can install with carthage or SPM. 126 | 127 | ### Carthage 128 | 129 | - Add the following to your *Cartfile*: 130 | 131 | ```bash 132 | github 'sgr-ksmt/once' 133 | ``` 134 | 135 | - Then run command. 136 | 137 | ## Communication 138 | - If you found a bug, please open an issue. :bow: 139 | - Also, if you have a feature request, please open an issue. :thumbsup: 140 | - If you want to contribute, submit a pull request.:muscle: 141 | 142 | ## License 143 | 144 | **Once** is under MIT license. See the [LICENSE](LICENSE) file for more info. 145 | --------------------------------------------------------------------------------