Skip to content

Instantly share code, notes, and snippets.

@peteranny
peteranny / Cartfile.patch.rb
Last active August 8, 2020 06:19
An example Podfile-like script which applies patches between Carthage checkout and build. https://medium.com/@tingyishih/ios-migrate-from-cocoapods-to-carthage-7be237e4cac0
#!/usr/bin/ruby -W0
=begin
This file is to replace Cartfile to achieve patches between Carthage checkout and build
Please run `./Cartfile.patch` to browse its usage
=end
require_relative "Cartfile.patch.utils"
carthage do
import PromiseKit
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let p = Promise.value(0) // A useless promise just for test
public class HelloWorld {
let hello = "Hello"
public init() {}
public func hello(to whom: String) -> String {
return "Hello \(whom)"
}
}
import XCTest
@testable import HelloWorldSDK
class HelloWorldSDKTests: XCTestCase {
func testHelloWorld() {
let hw = HelloWorld()
// test public method
XCTAssertEqual(hw.hello(to: "World"), "Hello World")
Pod::Spec.new do |s|
s.name = "HelloWorldSDK"
s.version = "0.0.1"
s.summary = "iOS SDK for Hello World"
s.description = "iOS SDK for Hello World, including example app"
s.homepage = "https://github.com/peteranny/"
s.license = "MIT"
s.author = "peteranny"
s.platform = :ios, "9.0"
s.swift_version = "4.2"
use_frameworks!
target 'HelloWorldExampleApp' do
platform :ios, '12.1'
pod 'HelloWorldSDK', :path => '.'
end
import UIKit
import HelloWorldSDK
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let label: UILabel = {
let label = UILabel()
public class HelloWorld {
let greet = "Hello"
public init() {}
public func hello(to whom: String) -> String {
return "\(greet) \(whom)"
}
public var helloColor: UIColor? {
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let label: UILabel = {
let label = UILabel()
label.frame.origin = CGPoint(x: 100, y: 100)
label.text = HelloWorld().hello(to: "World")
/* Use your asset */
@peteranny
peteranny / SimpleViewController.swift
Last active March 13, 2024 03:43
Combine-version twin of the MVVM data binding pattern in RxSwift. Referenced by: https://medium.com/@tingyishih/mvvm-data-binding-with-rxswift-single-interface-practice-1a7f5f1a655d
import Combine
import CombineCocoa // To allow publisher extensions such as button.tapPublisher
import UIKit
class SimpleViewController: UIViewController {
private let viewModel = SimpleViewModel()
private var cancellables: [AnyCancellable] = []
private let button = UIButton()
override func viewDidLoad() {