I don't know how to use the AutoreleasingUnsafePointer. I have the following code:
var myString: AutoreleasingUnsafePointer<NSString?>
myScanner.scanUpToCharactersFromSet(NSCharacterSet.newlineCharacterSet(), intoString: myString)
Now, what should I do to get the string from 'myString'? I know it can be nil, but I couldn't figure out a way to get the string value in case it wasn't nil. And the Swift unwrapping technique just only works with the Optional type.
Thanks!
The characters are visually similar, but don’t have the same linguistic meaning: print ( "These two characters aren't equivalent." ) // Prints "These two characters aren't equivalent." String and character comparisons in Swift aren’t locale-sensitive.
Substrings in Swift have most of the same methods as strings, which means you can work with substrings the same way you work with strings. However, unlike strings, you use substrings for only a short amount of time while performing actions on a string. When you’re ready to store the result for a longer time,...
To get the value using a key from a Swift Dictionary, use the following syntax. var value = myDictionary[key] The syntax is similar to accessing a value from an array using the index. Here, in case of the dictionary, key is playing the role of an index,
A string literal is a sequence of characters surrounded by double quotation marks ( " ). Use a string literal as an initial value for a constant or variable: Note that Swift infers a type of String for the someString constant because it’s initialized with a string literal value.
If the second parameter of scanUpToCharactersFromSet
is declared as autoreleasing unsafe pointer, i.e. AutoreleasingUnsafePointer<NSString?>
you should be able to invoke your function without making a pointer explicitly. Swift lets you use &
operator on an NSString?
variable to produce an autoreleasing unsafe pointer, like this:
var str : NSString? = nil
myScanner.scanUpToCharactersFromSet(NSCharacterSet.newlineCharacterSet(), intoString:&str)
This would give you str
as a "normal" optional NSString
, which you can unwrap using the regular unwrapping operators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With