Value of type 'String' has no member 'stringByTrimmingCharactersInSet'
The new syntax is like this:
var cString = hex.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased()
As a suggestion, you don't need to specify that cString
is a String, as this is assumed with the value you are assigning to it.
What is the new way to trim a String?
Swift3 inctroduced a lot of changes shortening api names and making them more 'swiftly'. Your code would look the following in swift3:
let st = s.trimmingCharacters(in: unwantedChars)
Error Value of type 'String' has no member 'URLbyAppending' with my Record Function
Your getDocumentsDirectory
function, which you should have included, apparently returns a string, not a URL. Fix it by using stringByAppendingPathComponent
.
Alternatively, you can change your getDocumentsDirectory
function to return a url directly and changing your calling to:
func getDocumentsDirectory() throws -> NSURL {
return try NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
}
let audioUrl = try getDocumentsDirectory().URLByAppendingPathComponent("recording.m4a")
Note that since getDocumentsDirectory can throw (URLForDirectory can throw) getDocumentsDirectory must be called with try.
Value type of string? Has no member components. (Struct)
There's no reason to use NSDictionary
here. Just use a native Swift dictionary (with a literal).
public struct Destinos {
public let idDestino : Int?
public let desDestino : String?
public func toDictionary() -> [String: Any?] {
return [
"idDestino": idDestino,
"desDestino": desDestino
]
}
}
As for generating your array, you have two issues:
1. components(seperatedBy:)
is misspelt
2. cadena.desDestino
is an is a String?
(Also known as a Optional<String>
) which hasn't been unwrapped. The nicest way to take care of this is to use optional chaining, and then use nil coalescence (??
) to make it an empty array in the case cadena.desDestino
is nil
.
var cadena = Destinos(
idDestino: 123,
desDestino: "HOLA, nada, algo, otra, cosa, mas que eso"
)
let array = cadena.desDestino?.components(separatedBy: ", ") ?? []
Value of type 'Tags' has no member 'lastUsed'
The problem is that the declarations of name
and lastUsed
have an invisible character (U+200B = "ZERO WIDTH SPACE") as the last character of the identifier.
Here is a short example demonstrating what seems to be a paradox. The first print statement does not compile, but the last one does:
struct Tags {
let name = "name"
}
print(Tags().name) // (1) Error: Value of type 'Foo' has no member 'name'
print(Tags().name) // (2) No error
Unfortunately, Xcode does not display this character, even if “Editor->Invisibles” is switched on. Opening the file in vi
shows the issue:
struct Tags {
let name<200b> = "name"
}
print(Tags().name) // (1) Error: Value of type 'Foo' has no member 'name'
print(Tags().name<200b>) // (2) No error
Note that invisible characters are allowed in identifier names, this has been discussed in the Swift forum.
The first print statement was created with Xcode's code completion and Xcode omits the trailing invisible character. I would consider that a bug.
The second print statement was created by carefully copying the name
identifier including the trailing invisible character.
Summary: Swift identifiers can contain invisible characters, but those do not work well with Xcode's code completion and cause only confusion. Rewriting all occurrences of those identifiers fixes the issue.
Related Topics
Revealviewcontroller() Always Returns Nil
How to Add a Lock Screen Widget (Requiring iOS 16) and Still Support iOS 15
How to Access All Images in a .Xcassets at Once
Can't Write Non Current User Objects by Pfuser Currentuser
I Want to Draw Custom Shape Like Apple Shape on UIview
Xcode UI Tests Can't Find Views That Are Added Programmatically
Fixing Low Fps in Swift Playground
iOS Swift Streaming App Does Not Play Music in Background Mode
Left-To-Right Mark Not Working in Swift
Nsmanagedobject Setter Giving Me [ Myobject Setname:]: Unrecognized Selector Sent to Instance
Svg Viewbox Height Issue on iOS Safari
Dynamic Cell Height with Sdwebimage
Swift (Beta 3) "Nsdictionary? Does Not Conform to Protocol 'Equatable'"