Skip to main content

Posts

Showing posts from April, 2020

CocoaPods: How to create CocoaPod

https://medium.com/@vialyx/create-cocoapod-using-swift-2685c7f119ac Như chúng ta đã biết, CocoaPods là một công cụ tuyệt vời và hữu ích, giúp quản lý, chia sẻ các thư viện lập trình một cách hiệu quả trong phát triển ứng dụng iOS, OS X. Số lượng người sử dụng CocoaPods ngày càng nhiều, cộng đồng hỗ trợ ngày càng đông. Các thư viện lập trình phổ biến trong iOS như: AFNetworking, Alamofire, SDWebImage, MBProgressHUD, SwiftyJSON... đều hỗ trợ CocoaPods cả. Tuy nhiên chúng ta thường chỉ dùng thư viện của người khác qua CocoaPods. Và đã bao giờ bạn tự hỏi: Làm thế nào để tạo ra một pod chia sẻ thư viện của riêng mình? Trong bài viết này, chúng ta sẽ cùng tìm hiểu điều đó. CocoaPods bản chất là một Ruby gem trong RubyGems . Để cài đặt CocoaPods, mở Terminal lên và chạy đoạn lệnh sau: sudo gem install cocoapods Step by Step Overview Việc tạo một thư viện bằng CocoaPods có thể chia thành 5 bước chính sau: Xác định ý tưởng, mục đích của thư viện pod mà bạn cần tạo. Sử dụng

Frame vs Bounds in iOS

This article is a repost of an answer I wrote on Stack Overflow . Short description frame = a view’s location and size using the parent view’s coordinate system ( important for placing the view in the parent) bounds = a view’s location and size using its own coordinate system (important for placing the view’s content or subviews within itself) Details To help me remember frame , I think of a picture frame on a wall . The picture frame is like the border of a view. I can hang the picture anywhere I want on the wall. In the same way, I can put a view anywhere I want inside a parent view (also called a superview). The parent view is like the wall. The origin of the coordinate system in iOS is the top left. We can put our view at the origin of the superview by setting the view frame’s x-y coordinates to (0, 0), which is like hanging our picture in the very top left corner of the wall. To move it right, increase x, to move it down increase y. To help me remember bound

SynchronizedArray - Block array

Khi add thêm phần tử vào mảng từ nhiều luồng khác nhau cùng tại một thời điểm sẽ dẫn đến lỗi mảng, chúng ta cần phải xử lý khoá mảng lại để trong một thời điểm chỉ xử lý một action mà thôi import Foundation /// A thread-safe array. public class SynchronizedArray<Element> {     private let queue = DispatchQueue(label: "io.zamzam.ZamzamKit.SynchronizedArray", attributes: .concurrent)     private var array = [Element]()     public init() { }     public convenience init(_ array: [Element]) {         self.init()         self.array = array     } } // MARK: - Properties public extension SynchronizedArray {     /// The first element of the collection.     var first: Element? {         var result: Element?         queue.sync { result = self.array.first }         return result     }     /// The last element of the collection.     var last: Element? {         var result: Element?         queue.sync { result = self.array.last }         return result