Skip to content

Instantly share code, notes, and snippets.

View ArchieR7's full-sized avatar
👨‍💻

Archie Chang ArchieR7

👨‍💻
View GitHub Profile
[self.KVOController observe:self
keyPath:NSStringFromSelector(@selector(observeObjectName))
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
//do something
}];
dismiss(animated: true, completion: nil)
@ArchieR7
ArchieR7 / asyncUnitTest.swift
Created June 16, 2017 05:39
unit test with async functions
func testAsyncFunction() {
let exp = expectation(description: "Async Expectation")
NetworkManager.shared.update(data: Data(), completeHandler: {
exp.fulfill()
})
waitForExpectations(timeout: 30, handler: nil)
}
import UIKit
struct UISetting {
static let blue = UIColor(colorLiteralRed: 21/255, green: 122/255, blue: 251/255, alpha: 1)
}
func setUpView() {
let loginButton = CircleButton()
loginButton.backgroundColor = UISetting.blue
}
@ArchieR7
ArchieR7 / podfile
Created June 26, 2017 02:08
CocoaPods with AdMob
pod 'Firebase/AdMob'
@ArchieR7
ArchieR7 / AppDelegate.swift
Created June 26, 2017 02:12
AppDelegate with AdMob
import Firebase
import GoogleMobileAds
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
GADMobileAds.configure(withApplicationID: Your_Ads_ApplicationID)
return true
}
func loadAdMob() {
GADRewardBasedVideoAd.sharedInstance().delegate = self
let request = GADRequest()
GADRewardBasedVideoAd.sharedInstance().load(request, withAdUnitID: AdUnitID)
}
@ArchieR7
ArchieR7 / CheckAdMob.swift
Created June 26, 2017 02:17
Check AdMob is ready
if GADRewardBasedVideoAd.sharedInstance().isReady {
GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self)
} else {
//do something
}
@ArchieR7
ArchieR7 / GADRewardBasedVideoAdDelegate.swift
Created June 26, 2017 02:20
AdMob Reward based video ad delegate
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didRewardUserWith reward: GADAdReward) {
//give user reward
}
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didFailToLoadWithError error: Error) {
print("Reward based video ad failed to load: \(error.localizedDescription)")
}
func rewardBasedVideoAdDidReceive(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
print("Reward based video ad is received.")