This file contains hidden or 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
// Credits: https://github.com/realm/realm-cocoa/issues/1159 | |
func compact() { | |
let tmpPath = Realm.Configuration.defaultConfiguration.fileURL!.appendingPathExtension("bak") | |
try! Realm().writeCopy(toFile: tmpPath) | |
try! FileManager.default.replaceItem(at: Realm.Configuration.defaultConfiguration.fileURL!, withItemAt: tmpPath, backupItemName: nil, options: .usingNewMetadataOnly, resultingItemURL: nil) | |
} | |
// Usage: | |
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { |
This file contains hidden or 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 UIView { | |
func traverseSubviewTree(action: (UIView) -> ()) { | |
for sv in self.subviews { | |
action(sv) | |
} | |
for sv in self.subviews { | |
sv.traverseSubviewTree(action) | |
} | |
} |
This file contains hidden or 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
var str = "one" | |
let actionOne = { [str = str] in | |
print("str = \(str)") | |
} | |
let actionTwo = { | |
print("str = \(str)") | |
} |
This file contains hidden or 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 String { | |
/** | |
Returns the same string ensuring digits are in Latin. | |
Useful in https requests, when the backend doesn't handle non-Latin digits. | |
Not for cross-locale real value conversions (e.g. 12,5 => 12.5). | |
*/ | |
var withNumbersLatinized: String { | |
get { | |
var selfASNSString = self as NSString | |
let pattern = "\\d+" |
This file contains hidden or 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
post_install do |installer| | |
# Your list of targets here. | |
myTargets = [‘Alamofire’, ‘FontBlaster’, ‘MenuItemKit’] | |
installer.pods_project.targets.each do |target| | |
if myTargets.include? target.name | |
target.build_configurations.each do |config| | |
config.build_settings[‘SWIFT_VERSION’] = ‘3.2’ | |
end | |
end |
This file contains hidden or 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
post_install do |installer| | |
targetsToOptimizeAtDebug = ['SwiftSoup'] | |
installer.pods_project.targets.each do |target| | |
if targetsToOptimizeAtDebug.include? target.name | |
target.build_configurations.each do |config| | |
if config.name == "Debug" | |
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Owholemodule' | |
end | |
end |
This file contains hidden or 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
var xml = "<ق>نص</ق>" | |
var pattern = "<ق>(.*)</ق>" | |
var regex = try? NSRegularExpression(pattern: pattern, options: .caseInsensitive) | |
var textCheckingResult: NSTextCheckingResult? = regex?.firstMatch(in: xml, options: [], range: NSRange(location: 0, length: xml.count)) | |
var matchRange: NSRange? = textCheckingResult?.range(at: 1) | |
var match: String? = nil | |
if let aRange = matchRange { | |
match = (xml as NSString).substring(with: aRange) | |
} | |
print("Found string '\(match ?? "")'") |
This file contains hidden or 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 queryParams = "{query}{&page, per_page, sort, order}" | |
let urlString = "https://api.github.com/search/repositories?q=" + queryParams.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! | |
let url = URL(string: urlString)! |
OlderNewer