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
// TODO: - This is often used combination in regular projects to get access to project resources | |
let mainBundle = Bundle.main | |
print("identifier: \(String(describing: mainBundle.bundleIdentifier))") | |
// TODO: - Find nessesary bundle, for example by name | |
let allBundles = Bundle.allBundles | |
print("bundles: \(allBundles)") |
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 mainBundle = Bundle.main | |
print("identifier: \(String(describing: mainBundle.bundleIdentifier))") |
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 allBundles = Bundle.allBundles | |
print("bundles: \(allBundles)") |
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
class User { | |
var id: UInt | |
var name: String | |
init(id: UInt, name: String) { | |
self.id = id | |
self.name = name | |
} | |
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 identifierExample = "com.apple.dt.playground.stub.iOS_Simulator.Bundle-FF59A7A5-B1B5-4AEB-AE77-2334AF184375" | |
let identifiedBundle = Bundle(identifier: identifierExample) | |
print("identifier bundle: \(String(describing: identifiedBundle))") |
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
/* | |
Note: Result of loadNibNamed is array of common level views from Nib | |
Usually the view you need is the first | |
*/ | |
let customView = classBundle.loadNibNamed("CustomView", owner: nil, options: nil)?.first |
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
guard let jsonURL = classBundle.url(forResource: "users", withExtension: "json"), | |
let data = try? Data(contentsOf: jsonURL), | |
let objects = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) else { fatalError("haven't users.json file") } | |
print("objects: \(objects)") | |
/* | |
objects: { | |
users = ( | |
{ | |
id = 190; |
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 localizations = classBundle.localizations | |
print("localizations: \(localizations)") |
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
import Foundation | |
let fileSizeInBytes: Int64 = 1924284 | |
let byteFormatter = ByteCountFormatter() | |
print("Default settigs: \(byteFormatter.string(fromByteCount: fileSizeInBytes))") | |
// Default settigs: 1.9 MB | |
byteFormatter.allowedUnits = .useKB | |
print("Change allowedUnits settig: \(byteFormatter.string(fromByteCount: fileSizeInBytes))") |
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 dateComponentsFormatter = DateComponentsFormatter() | |
dateComponentsFormatter.unitsStyle = .full | |
dateComponentsFormatter.includesApproximationPhrase = true | |
dateComponentsFormatter.includesTimeRemainingPhrase = true | |
dateComponentsFormatter.allowedUnits = [.minute, .hour] | |
let timeIntervalInPast: TimeInterval = -3666 | |
let nowDate = Date() | |
let pastDate = nowDate.addingTimeInterval(timeIntervalInPast) |