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
// Decoding User Info | |
func decodeUserInfo(from data: Data) -> Result<User, Failure> { | |
let decoder = JSONDecoder() | |
let decodedData = try? decoder.decode(DecodedUserInfo.self, from: data) | |
guard let userData = decodedData?.person else { print("Errors while decoding UserData: \(Failure.failedDecodingFile.errorDescription)"); return .failure(.failedDecodingFile)} | |
let user = User(userID: userData.id, userName: userData.username.content, iconServer: userData.iconserver, iconFarm: userData.iconfarm) | |
_ = user.iconURL | |
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 retrieveUserInfo() throws -> User { | |
let plistDecoder = PropertyListDecoder() | |
let filePath = FileManager.documentsDirectory | |
let file = filePath.appendingPathComponent("SavedUserData").appendingPathExtension("plist") | |
guard let retrievedData = try? Data(contentsOf: file) else { print("Errors: \(Failure.missingFile.errorDescription)"); throw Failure.missingFile } | |
guard let decodedUserData = try? plistDecoder.decode(User.self, from: retrievedData) else { print("Error: \(Failure.failedDecodingFile.errorDescription)"); throw Failure.failedDecodingFile} |
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 PhotoDetailsVC: UIScrollViewDelegate { | |
/// Returns the view that is expected to be zoomed | |
/// - Parameter scrollView: A view that allows the scrolling and zooming of its contained views. | |
func viewForZooming(in scrollView: UIScrollView) -> UIView? { | |
return imageView | |
} | |
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 { | |
// Usage: | |
// let scaledImage = image.scale(newWidth: 960.0) | |
func reduceImageSize(to newWidth: CGFloat) -> UIImage { | |
if self.size.width == newWidth { | |
return self | |
} | |
// Calculates the scaling factor |
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 decodeDatefrom(_ unixTime: String) -> String? { | |
// converts comment date into meaningful date | |
var decodedDate: String? | |
if let unixTime = Double(unixTime) { | |
let dateFormatter = DateFormatter() | |
let date = Date(timeIntervalSince1970: unixTime) |
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
// Lazy Closures | |
class Person { | |
let name: String | |
init(name: String) { | |
self.name = name | |
} | |
// Remember to add the closing brace '()' at the end of the closure declaration |
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
// Lazy methods | |
class Person { | |
let name: String | |
init(name: String) { | |
self.name = name |
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
class MusicPlayer { | |
init() { | |
print("Music Player has started") | |
} | |
} | |
class Singer { | |
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
class Testing: UIViewController { | |
let fileManager = FileManager.default | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
if let path = Bundle.main.resourcePath { | |
guard let items = try? fileManager.contentsOfDirectory(atPath: path) else { print("Path is not available"); return } | |
for item in items { |