This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getHDDSize() -> CGFloat { | |
do { | |
let fileAttributes = try FileManager.default.attributesOfFileSystem(forPath: "/") | |
if let size = fileAttributes[FileAttributeKey.systemSize] as? CGFloat { | |
return size | |
} | |
} catch { } | |
return 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <objc/runtime.h> | |
unsigned int numberOfProperties = 0; | |
objc_property_t *propertyArray = class_copyPropertyList([YourClass class], &numberOfProperties); | |
for (NSUInteger i = 0; i < numberOfProperties; i++) { | |
objc_property_t property = propertyArray[i]; | |
NSString *name = [[NSString alloc] initWithUTF8String:property_getName(property)]; | |
NSString *attributesString = [[NSString alloc] initWithUTF8String:property_getAttributes(property)]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for family: String in UIFont.familyNames { | |
print("\(family)") | |
for names: String in UIFont.fontNames(forFamilyName: family) { | |
print("== \(names)") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
func resizeImage(_ image: UIImage, newWidth: CGFloat) -> UIImage? { | |
let scale = newWidth / image.size.width | |
let newHeight = image.size.height * scale | |
UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight)) | |
image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight)) | |
let newImage = UIGraphicsGetImageFromCurrentImageContext() | |
guard let image = newImage else { return nil } | |
UIGraphicsEndImageContext() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Photos | |
func checkIfAuthorizedToAccessPhotos(_ handler: @escaping (_ isAuthorized: Bool) -> Void) { | |
switch PHPhotoLibrary.authorizationStatus() { | |
case .notDetermined: | |
PHPhotoLibrary.requestAuthorization{ status in | |
switch status { | |
case .authorized: | |
handler(true) | |
default: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TAGS="TODO:|FIXME:" | |
echo "searching ${SRCROOT} for ${TAGS}" | |
find "${SRCROOT}" \( -name "*.swift" \) -print0 \ | |
| xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" \ | |
| perl -p -e "s/($TAGS)/ warning: \$1/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func randomColor(_ seed: String) -> UIColor { | |
var total: Int = 0 | |
for u in seed.unicodeScalars { | |
total += Int(UInt32(u)) | |
} | |
srand48(total * 200) | |
let r = CGFloat(drand48()) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIColor { | |
static func random() -> UIColor{ | |
return UIColor( | |
red: CGFloat(drand48()), | |
green: CGFloat(drand48()), | |
blue: CGFloat(drand48()), | |
alpha: 1.0 | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let columns: CGFloat = 2.0 | |
let inset: CGFloat = 15.0 | |
let spacing: CGFloat = 2.0 | |
let lineSpacing: CGFloat = 4.0 | |
extension PinboardRootViewController : UICollectionViewDelegateFlowLayout { | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |