What is the equivalent of a Java HashMapString,Integer in Swift
I believe you can use a dictionary. Here are two ways to do the dictionary part.
var someProtocol = [String : Int]()
someProtocol["one"] = 1
someProtocol["two"] = 2
or try this which uses type inference
var someProtocol = [
"one" : 1,
"two" : 2
]
as for the for loop
var index: Int
for (e, value) in someProtocol {
index = value
}
Class convert HashMap in java to NSDictionary in swift
Looks good so far, although unless there's a specific reason to keep the dictionary-based nature of the class, you really might want to consider something much simpler, like:
class Status {
var count : Int?
var active : Bool?
var typingIndicator : Bool?
var profileName : String?
}
It's far quicker, far simpler, and far more legible.
How to create a new data with both string part and a data in bytes, in Swift?
Thanks everyone who answered me, I've found a solution. I created a structure called DataPart with a string and data, and put that parameter to my Alamofire request with parameter name.
"What is the equivalent of a Java HashMap<String,Integer> in Swift" this entry helped me a lot in case you are wondering.
J2ObjC JavaUtilHashMap Not Showing in Swift
I'm not a Swift developer and so don't have a definitive answer, but Java developers recommend using the interface rather than the implementation class in a public API (Effective Java, Item 18). So you may have better luck defining metadata's type as java.util.Map, rather than HashMap.
What is the equivalent data type for byte in iOS swift?
The data type is Unsigned Int 8 (UInt8).
var byte:UInt8 = 0xAF
For a string of bytes:
var bytes:[UInt8] = [0xAF,0xAB]
For the bytes from data:
var data = Data()
var bytes = data.bytes //[UInt8]
What is the Android Java equivalent of a Swift Dictionary?
http://docs.oracle.com/javase/tutorial/collections/interfaces/map.html
A Map is an object that maps keys to values. A map cannot contain duplicate keys: Each key can map to at most one value.
Map<String,String> toppings = new HashMap<>();
toppings.put("Onions","Red");
toppings.put("Peppers","Green");
Maps are great, you will end up using them a lot :)
Java HashMap to iOS
You can do
testHashMap[@"FifthKey"] = @"FifthItem";
And read them with
testHashMap[@"FifthKey"];
MNSMutableDictionary is a great way to store and read dynamic data.
But if you have static data - just use NSDictionary.
If your data is mostly static but you change it sometimes - still use NSDictionary and convert to it mutable using [dict mutableCopy], then add new items there and convert it back using [mutableDict copy].
What is the equivalent of Java charAt() in Swift?
Use the equivalent of an "enhanced" loop:
for c in s {
if(c == 'A') ...
}
Related Topics
Android: Why Setvisibility(View.Gone); or Setvisibility(View.Invisible); Do Not Work
How to Avoid Unnecessary Firestore Reads with Cache
How to Remove a Specific Element from a JSONarray
How Many Ways to Convert Bitmap to String and Vice-Versa
Enabling Specific Ssl Protocols with Android Webviewclient
Android Drawable Speech Bubble
Android 3.1 Usb-Host - Broadcastreceiver Does Not Receive Usb_Device_Attached
Caused By: Java.Lang.Classnotfoundexception: Didn't Find Class in Firebase Phone Authentication
Networksecurityconfig: No Network Security Config Specified -- Android 7.0 Error
How to Programmatically Add Views and Constraints to a Constraintlayout
Parcelable and Inheritance in Android
How to Match Nested Brackets with a Regex Without Using Recursion or Balancing Groups