Unwrap value from Dictionary in Swift

Related tags

Guides JHUnwrap
Overview

JHUnwrap

Unwrap value from Dictionary in Swift

Example

    let dict: Dictionary<String, Any> = [
        "name": "Lilei",
        "age": 20,
        "sex": false,
        "height": 180.5,
        "array": [1,2,3],
        "dic": ["a":123, "b": "hello", "c": true]
    ]
    
    for (key, _) in dict {
        print(key, "=", dict[key] as Any, ",", type(of: dict[key]))
    }
    print("================\n")
//    array = Optional([1, 2, 3]) , Optional<Any>
//    dic = Optional(["b": "hello", "a": 123, "c": true]) , Optional<Any>
//    age = Optional(200) , Optional<Any>
//    sex = Optional(false) , Optional<Any>
//    name = Optional("lilei") , Optional<Any>
    
    print(dict["name"].jh_string) // Swift.String
    print(dict["name"].jh_stringValue)
    print(dict["name"].jh_int)
    print(dict["name"].jh_bool)
    print(dict["name"].jh_array)
    print(dict["name"].jh_dict)
    print("================\n")
//    Lilei
//    Lilei
//    9223372036854775807
//    false
//    []
//    [:]
You might also like...
A collection of Swift tips & tricks that I've shared on Twitter

⚠️ This list is no longer being updated. For my latest Swift tips, checkout the "Tips" section on Swift by Sundell. Swift tips & tricks ⚡️ One of the

An Xcode playground showcasing the new features in Swift 4.0.
An Xcode playground showcasing the new features in Swift 4.0.

What’s new in Swift 4 An Xcode playground showcasing the new features in Swift 4.0. As seen in the What’s New in Swift session at WWDC 2017. Written b

📖 Design Patterns implemented in Swift 5.0

📖 Design Patterns implemented in Swift 5.0

List of awesome iOS & Swift stuff!!
List of awesome iOS & Swift stuff!!

Awesome iOS Developer Feel free to fork this repository and pull requests!! 🔎 Content Coding Convention Swift Lint Design Pattern Adaptor Delegation

This repo shows how to set up and use GitHub Actions as a CI for Swift Packages
This repo shows how to set up and use GitHub Actions as a CI for Swift Packages

SwiftPackageWithGithubActionsAsCI This repo shows how to set up and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib Li

The first HackingWithSwift project from the 100 Days of Swift series.

StormViwer A gallery to display images included in the app's internal assets folder. This is my first ever swift project and it is a part of the serie

Swift optional desugaring

Swift optional desugaring Setup Make sure you have installed Swift according to the instructions from you earlier assignment. Open a terminal / consol

Mini-application iOS native avec Xcode et Swift exploitant l'architecture MVVM et le framework Combine d'Apple pour la mise en place de la programmation réactive fonctionnelle, le tout avec UIKit.
Mini-application iOS native avec Xcode et Swift exploitant l'architecture MVVM et le framework Combine d'Apple pour la mise en place de la programmation réactive fonctionnelle, le tout avec UIKit.

iOS (Swift 5): Test MVVM avec Combine et UIKit L'architecture MVVM et la programmation réactive fonctionnelle sont très utlisées dans le développement

iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit
iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit

iOS (Swift 5): MVVM test with Combine and UIKit MVVM and functional reactive programming (FRP) are very used in iOS development inside companies. Here

Owner
HaoCold
Change the world, Just code it.
HaoCold
Lightweight Framework for using Core Data with Value Types

Features Uses Swift Reflection to convert value types to NSManagedObjects iOS and Mac OS X support Use with structs Works fine with let and var based

Benedikt Terhechte 456 Nov 6, 2022
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

Realm 16.9k Dec 30, 2022
Sweet-swift - Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper Functions and Common Utilities

Sweet Swift Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper F

Yanzhan Yang 2 Feb 6, 2022
Airbnb's Swift Style Guide.

Airbnb Swift Style Guide Goals Following this style guide should: Make it easier to read and begin understanding unfamiliar code. Make code easier to

Airbnb 1.8k Jan 3, 2023
LinkedIn's Official Swift Style Guide

Swift Style Guide Make sure to read Apple's API Design Guidelines. Specifics from these guidelines + additional remarks are mentioned below. This guid

LinkedIn 1.4k Jan 5, 2023
The Official raywenderlich.com Swift Style Guide.

The Official raywenderlich.com Swift Style Guide. Updated for Swift 5 This style guide is different from others you may see, because the focus is cent

raywenderlich 12.5k Jan 3, 2023
A self-taught project to learn Swift.

30 Days of Swift Hi Community I am Allen Wang, a product designer and currently learning Swift. This project was totally inspired by Sam Lu's 100 Days

Allen Wang 11.4k Dec 31, 2022
Explanations and samples about the Swift programming language

About Swift Contents Explanations and samples about: Swift Programming Language Swift Standard Library Target audience Developers familiar with object

Nicola Lancellotti - About 74 Dec 29, 2022
A collection useful tips for the Swift language

SwiftTips The following is a collection of tips I find to be useful when working with the Swift language. More content is available on my Twitter acco

Vincent Pradeilles 929 Dec 10, 2022
Swift Featured Projects in brain Mapping

Swift 开源精选   自 2014年 WWDC 发布 Swift 语言以来,本项目 一直致力于将主流 Swift 中文学习、开发资源汇集于此,并且尽力紧密地跟踪、甄选优秀 Swift 开源项目,以方便开发者快速获得并使用。考虑 Swift 已经正式发布超过四年半(更无力管理维护海量的 Swift

iPader 15.8k Jan 9, 2023