[SWIFT] When you want to check whether the contents of a property can be converted to a specific type

code

Swift

let string = "AIUEO"
let int = 10

//When you want to find out if it is a string
if String(string) != nil{
    print("String type")
} else{
    print("Not of type String")
}
//String type

//When you want to check if it is an Int type
if Int(string) != nil{
    print("String type")
} else{
    print("Not of type String")
}
//Not of type String

How to check the type

//When you want to check if it is a String type
if int is String{
    print("String type")
} else{
    print("Not of type String")  //This is called
}

//When you want to check if it is an Int type
if string is Int{
    print("Int type")   
} else{
    print("Not an Int type")     //This is called
}

Recommended Posts

When you want to check whether the contents of a property can be converted to a specific type
A memo when you want to clear the time part of the calendar
I want to be aware of the contents of variables!
When you want to change the MySQL password of docker-compose
When you want to change the wording to be displayed when making a select box from enum
How to check for the contents of a java fixed-length string
[Swift] When you want to know if the number of characters in a String matches a certain number ...
A collection of patterns that you want to be aware of so as not to complicate the code
Object-oriented design that can be used when you want to return a response in form format
When you want Rails to disable a session for a specific controller only
When you want to add a string type column with a limited length with the `rails generate migration` command
An example of a small work when you want to divide the definition value according to the environment but do not want to be aware of it
Set the time of LocalDateTime to a specific time
I want to var_dump the contents of the intent
When you want to use the method outside
Pay attention to the boundary check of the input value when using the float type
I managed to get a blank when I brought the contents of Beans to the textarea
[rails] After option useful when you want to change the order of DB columns
[java tool] A useful tool when you want to send the ipmsg log of PC-A to the specified PC on a regular basis.
Check if a string can be converted to an int without using Integer # parseInt
Sample code to assign a value in a property file to a field of the expected type
A memo to check when you try to use Lombok
I want to get a list of the contents of a zip file and its uncompressed size
Check the dependency of a specific maven artifact in Coursier
[Ruby] How to retrieve the contents of a double hash
[Controller] I want to retrieve the numerical value of a specific column from the DB (my memo)
Comparison of version strings (Java implementation) when you want to branch the process between two versions
A trick when you want to insert a lot of line breaks and tabs when substituting a character string
When you want to ZIP download the image data saved locally
A story that could be implemented neatly by using polymorphism when you want to express two types of data in one table
[RSpec] When you want to use the instance variable of the controller in the test [assigns is not recommended]
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java
[Rails + Webpacker] I want to use images of assets! Until you can view the image in Vue.js
Summary of means when you want to communicate with HTTP on Android
[Java] How to get to the front of a specific string using the String class
I want you to use Enum # name () for the Key of SharedPreference
Check the contents of the Java certificate store
Check the contents of params with pry
Memo: [Java] Check the contents of the directory
What to do when you want to delete a migration file that is "NO FILE"
If you want to satisfy the test coverage of private methods in JUnit
Corresponds to a property whose type is an array when empty using JsonDeserializer
How to create a route directly from the URL you want to specify + α
[Android] I want to create a ViewPager that can be used for tutorials
[Rails / ActiveRecord] I want to validate the value before the type is converted (_before_type_cast)
Rails6 I want to make an array of values with a check box
I want to see the contents of Request without saying four or five
I want to recursively get the superclass and interface of a certain class
Be absolutely careful when putting the result of and / or in a variable!
Summary of copy and paste commands used when you want to delete the cache in iOS application development anyway
Even if I want to convert the contents of a data object to JSON in Java, there is a circular reference ...
[Ruby] When you want to assign the result obtained by conditional branching to a variable and put it in the argument
I want you to put the story that the error was solved when you stabbed the charger in the corner of your head
A story that people who did iOS solidly may be addicted to the implementation of Listener when moving to Android