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
struct User: Codable { | |
let name: String | |
let color: Color? | |
enum Color: String, Codable { | |
case red = "RED" | |
case yelllow = "YELLOW" | |
case blue = "BLUE" | |
} | |
} |
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
// { | |
// "name": "Kermaine", | |
// "color": "RED", | |
// "number": 14 | |
// } | |
let data = requestData() | |
let decoder = JSONDecoder() | |
let object = try? decoder.decode(User.self, from: data) |
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
// { | |
// "name": "Janine", | |
// "color": "GREEN" | |
// } | |
let data = requestData() | |
let decoder = JSONDecoder() | |
let object = try? decoder.decode(User.self, from: data) | |
print(object) // nil |
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
// This data contains the following JSON data | |
// { | |
// "name": "Mario", | |
// "color": "YELLOW" | |
// } | |
let data = requestData() | |
let decoder = JSONDecoder() | |
let object = try? decoder.decode(User.self, from: data) |
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
struct User: Codable { | |
let name: String | |
let color: Color | |
enum Color: String, Codable { | |
case red = "RED" | |
case yelllow = "YELLOW" | |
case blue = "BLUE" | |
} | |
} |
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
<key>LSApplicationQueriesSchemes</key> | |
<array> | |
<string>instagram-stories</string> | |
</array> |
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 deeplink = URL(string: "instagram-stories://share")! | |
let canOpen = UIApplication.shared.canOpenURL(deeplink) | |
if canOpen { | |
UIApplication.open(deeplink, options: [:]) | |
} else { | |
// Handle error | |
} |
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 imageData = image.pngData() | |
let pasteboardItem: [[String : Any]] = [["com.instagram.sharedSticker.backgroundImage" : imageData]] | |
UIPasteboard.general.setItems(pasteboardItem, options: [:]) |
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
func createInstagramStoriesSharing(for image: UIImage) -> URL? { | |
guard let url = URL(string: "instagram-stories://share") else { return nil } | |
// Add image to Pasteboard | |
let imageData = image.pngData() | |
let pasteboardItems: [[String: Any]] = [["com.instagram.sharedSticker.backgroundImage": image]] | |
// Update with new pasteboard items | |
UIPasteboard.general.setItems(pasteboardItems, options: [UIPasteboard.OptionsKey.expirationDate: Date().addingTimeInterval(60)]) | |
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
struct Point { | |
let x: Int, y: Int | |
} | |
let p = Point(x: 21, y: 30) | |
let mirror = Mirror(reflecting: p) | |
print(mirror) // Mirror for Point | |
print(mirror.children.first) // Optional((label: Optional("x"), value: 21)) |