Skip to content

Instantly share code, notes, and snippets.

@adamawolf
adamawolf / Apple_mobile_device_types.txt
Last active July 30, 2024 04:43
List of Apple's mobile device codes types a.k.a. machine ids (e.g. `iPhone1,1`, `Watch1,1`, etc.) and their matching product names
i386 : iPhone Simulator
x86_64 : iPhone Simulator
arm64 : iPhone Simulator
iPhone1,1 : iPhone
iPhone1,2 : iPhone 3G
iPhone2,1 : iPhone 3GS
iPhone3,1 : iPhone 4
iPhone3,2 : iPhone 4 GSM Rev A
iPhone3,3 : iPhone 4 CDMA
iPhone4,1 : iPhone 4S
@iamjason
iamjason / us-states-array
Created December 29, 2014 01:31
Swift US States Array
let state = [ "AK - Alaska",
"AL - Alabama",
"AR - Arkansas",
"AS - American Samoa",
"AZ - Arizona",
"CA - California",
"CO - Colorado",
"CT - Connecticut",
"DC - District of Columbia",
"DE - Delaware",
@fuxingloh
fuxingloh / UILabelCountLines.swift
Last active June 4, 2024 08:09
iOS Swift: How to check if UILabel is truncated? Calculate number of lines for UILabel
func countLabelLines(label: UILabel) -> Int {
// Call self.layoutIfNeeded() if your view uses auto layout
let myText = label.text! as NSString
let rect = CGSize(width: label.bounds.width, height: CGFloat.greatestFiniteMagnitude)
let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: label.font], context: nil)
return Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight))
}
internal let DEFAULT_MIME_TYPE = "application/octet-stream"
internal let mimeTypes = [
"html": "text/html",
"htm": "text/html",
"shtml": "text/html",
"css": "text/css",
"xml": "text/xml",
"gif": "image/gif",
"jpeg": "image/jpeg",
@zacwest
zacwest / ios-font-sizes.swift
Last active July 17, 2024 21:39
iOS default font sizes - also available on https://www.iosfontsizes.com
let styles: [UIFont.TextStyle] = [
// iOS 17
.extraLargeTitle, .extraLargeTitle2,
// iOS 11
.largeTitle,
// iOS 9
.title1, .title2, .title3, .callout,
// iOS 7
.headline, .subheadline, .body, .footnote, .caption1, .caption2,
]
@gonzalezreal
gonzalezreal / ios-cell-registration-swift.md
Last active March 13, 2024 15:18
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@aaadonai
aaadonai / DocumentType.swift
Created April 19, 2016 01:02
A Swift enum that recognizes basic mimetypes in a NSData
// Inspired by: http://stackoverflow.com/questions/4147311/finding-image-type-from-nsdata-or-uiimage/5042365#5042365
import Foundation
enum DocumentType: String {
case jpeg = "image/jpeg"
case png = "image/png"
case gif = "image/gif"
case tiff = "image/tiff"
@ylem
ylem / CenterItemInCollectionView.playground
Last active January 5, 2024 03:28
Scrolling item on a horizontal UICollectionView, stopped item on center of screen.
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
class WLCollectionCell: UICollectionViewCell {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@inamiy
inamiy / struct-CodingKeys
Created June 21, 2017 08:02
Swift 4 Decodable + `struct CodingKeys`
import Foundation
struct User: Decodable {
let name: String
let age: Int?
// private enum CodingKeys: String, CodingKey {
// case name
// case NAME
// }
@UglyBlueCat
UglyBlueCat / XCUIElement+GentleSwipe.swift
Created January 19, 2018 15:32
Recently I found that XCUIElement.swipeUp() was far too violent, swiping way past the element in the UI I wanted my test to tap, so I wrote an extension to XCUIElement that swiped gently using XCUIElement.press(forDuration:thenDragTo:)
//
// XCUIElement+GentleSwipe.swift
//
// Created by Robin Spinks on 11/10/2017.
//
import Foundation
import XCTest
extension XCUIElement