Skip to content

Instantly share code, notes, and snippets.

View priore's full-sized avatar

Prioregroup.com priore

View GitHub Profile
@priore
priore / create_xcframework.sh
Created April 10, 2024 13:56
Script to create multiple Archs XCFramework from your native library code
#!/bin/sh
#
# BUILD PLATFORM SPECIFIC FRAMEWORKS
#
# rember before use: chmod +x create_xcframework.sh
# iOS devices
xcodebuild archive \
-scheme "MyLibrary iOS" \
@priore
priore / String-Extensions.swift
Last active November 25, 2022 18:01
Take an element of the json by key/value and in any position it is
public extension String {
/// Search a json key/value and return the relative full json object
func searchAndDecode<T: Codable>(key: String?, value: String?) -> [T]? {
guard let key, let value else { return nil }
let pattern = "\\{[^}]*?\"\(key)\".*\"\(value)\"[^}]*\\}"
guard let list = self.replacingOccurrences(of: "{", with: "{\n").capture(pattern: pattern),
let data = "[\(list.joined(separator: ","))]".data(using: .utf8),
let items = try? JSONDecoder().decode([T].self, from: data)
else { return nil }
return items
@priore
priore / WeakRef.swift
Created May 19, 2020 13:20
Thread Safe Weak Ref Queue
import Foundation
class WeakRef<T> where T: AnyObject {
private let queue = DispatchQueue(label: "ThreadSafeWeakRef.queue", attributes: .concurrent)
private(set) weak var _object: T?
weak var object: T? {
var result: T?
@priore
priore / Data+Extension.swift
Created April 26, 2020 16:56
Retrieve the content-type from the data signature
// recognized content-type
private let data_sign = [
"7z¼¯'": "application/x-7z-compressed",
"AIFF": "audio/x-aiff",
"AVI": "video/x-msvideo",
"BM": "image/bmp",
"BZh": "application/x-bzip2",
"MSCF": "application/vnd.ms-cab-compressed",
"ITSF": "application/vnd.ms-htmlhelp",
"!<arch>": "application/x-debian-package",
@priore
priore / data+extension.swift
Created April 24, 2020 01:13
Passing Decodable object as generic parameter
extension Decodable
{
init(_ data: Data) throws {
self = try JSONDecoder().decode(Self.self, from: data)
}
}
extension Data
{
func toObject<T>() throws -> T?
@priore
priore / logs.swift
Created July 23, 2018 12:21
Console logging output in a file
class ConsoleLog {
// to log even when a device is not connected to xcode
// it generates a file that you can then download from the Organizer
// select Devices -> select device -> select app -> Dowload container
// after you can able show the content of file and you navigate
// to Document folder for get the log file.
static func logToFile() {
#if DEBUG
if !self.isXcode() {
@priore
priore / MyCustomShare.swift
Created May 11, 2018 09:40
Custom action for a specific share types
//
// custom action for a specific share types
//
class MyCustomShare: NSObject, UIActivityItemSource {
static func share() {
let vc = UIViewController.topViewController()
@priore
priore / ENBaseObject.swift
Created May 11, 2018 09:38
MySQL helper and base object definition
//
// ENBaseObject.swift
//
import OHMySQL // https://github.com/oleghnidets/OHMySQL
import EVReflection // https://github.com/evermeer/EVReflection
class ENBaseObject: EVObject, OHMappingProtocol {
static var table: String {
return "\(String(describing: self).dropFirst(2))"
@priore
priore / Swift+HTML.swift
Last active May 5, 2018 06:51
HTML string to NSAttributedString
// Swift 4
extension String {
func toAttributedString(color: UIColor?, font: UIFont?) -> NSAttributedString {
do {
var string = self
if color != nil, font != nil {
string = """
@priore
priore / UIWebView+Height.h
Created March 31, 2017 14:21
UIWebView get height
// file: "UIWebView+Height.h"
#import <UIKit/UIKit.h>
typedef void(^WebViewContentLoaded)(NSString *html, CGSize scrollSize);
@interface UIWebView (Height) <UIWebViewDelegate>
@property (nonatomic, copy) WebViewContentLoaded webLoadedBlock;