Cannot invoke `join` with an argument list of type (String, [String]) in Swift 2.0
let separator = " / "
let outputString = separator.join(specializationTitles)
With Xcode7beta6:
specializationTitles.joinWithString(" / ")
With Xcode7 release version:
specializationTitles.joinWithSeparator(" / ")
Cannot invoke 'append' with an argument list of type'(String)'
The problem is that venues[venueIndex].rooms
is not a [String]
but a [String]?
. Optionals don’t have an append
method – the value wrapped inside them might, but they don’t.
You could use optional chaining to do the append in the case where it isn’t nil
:
venues[venueIndex].rooms?.append(room)
But you may instead want to initialize rooms
to an empty index instead when it is nil
, in which case you need to do a slightly messier assignment rather than an append:
venues[venueIndex].rooms = (venues[venueIndex].rooms ?? []) + [room]
However, it is worth asking yourself, does rooms
really need to be optional? Or could it just be a non-optional array with a starting value of empty? If so, this will likely simplify much of your code.
cannot invoke reduce with an argument list of type swift 2.0
reduce()
is a method for collections such as arrays so you have to call it on the list of the characters you can access using the characters
property of the string, not on the whole string itself:
let escaped = string.characters.reduce("") { string, character in
string + (character == mark ? "\(mark)\(mark)" : "\(character)")
}
Realm Cannot invoke 'add' with an argument list of type '(Person)'
This is just a summary of what I said in the comments:
Use Object
as a subclass as it is necessary for a class to be a model in Realm.
Cannot invoke 'reduce' with an argument list of type '(String, (String) - String)'
Your closure will be receiving two parameters and you're only using one ($0). You could use $0.0 in the closure or simply use the string constructor that does the same thing without reduce:
func times(_ n: Int) -> String
{ return String(repeating:self, count:n) }
OR, if you want to use Python like multiplication to repeat a string, you could add an operator:
extension String
{
static func *(lhs:String,rhs:Int) -> String
{ return String(repeating:lhs, count:rhs) }
}
// then, the following will work nicely:
"blah " * 10 // ==> "blah blah blah blah blah blah blah blah blah blah "
IOS9 - cannot invoke 'count' with an argument list of type '(String)'
In swift2 they did some changes on count
this is the code for swift 1.2:
let test1 = "ajklsdlka"//random string
let length = count(test1)//character counting
since swift2 the code would have to be
let test1 = "ajklsdlka"//random string
let length = test1.characters.count//character counting
In order to be able to find the length of an array.
This behaviour mainly happens in swift 2.0 because String
no longer conforms to SequenceType
protocol while String.CharacterView
does
Keep in mind that it also changed the way you are iterating in an array:
var password = "Meet me in St. Louis"
for character in password.characters {
if character == "e" {
print("found an e!")
} else {
}
}
So be really careful although most likely Xcode is going to give you an error for operations like these one.
So this is how your code should look in order to fix that error you are having (cannot invoke 'count' with an argument list of type '(String)'):
let index = rgba.startIndex.advancedBy(1)
let hex = rgba.substringFromIndex(index)
let scanner = NSScanner(string: hex)
var hexValue: CUnsignedLongLong = 0
if scanner.scanHexLongLong(&hexValue)
{
if hex.characters.count == 6 //notice the change here
{
red = CGFloat((hexValue & 0xFF0000) >> 16) / 255.0
green = CGFloat((hexValue & 0x00FF00) >> 8) / 255.0
blue = CGFloat(hexValue & 0x0000FF) / 255.0
}
else if hex.characters.count == 8 //and here
{
red = CGFloat((hexValue & 0xFF000000) >> 24) / 255.0
green = CGFloat((hexValue & 0x00FF0000) >> 16) / 255.0
blue = CGFloat((hexValue & 0x0000FF00) >> 8) / 255.0
alpha = CGFloat(hexValue & 0x000000FF) / 255.0
}
Swift 2.0 Cannot invoke 'map' with argumet list of type ([AnyObject],(_) - _)
map
is now a member function on the CollectionType protocol.
Try return (self.object as! [AnyObject]).map { JSON($0) }
Cannot invoke 'CGPointMake' with an argument list of type '((), CGFloat)' received in Swift
You have to cast it CGFloat
_minThumb.center = CGPointMake(CGFloat(self.xForValue(selectedMinimumValue)), self.center.y);
Cannot invoke 'SecPolicyCreateSSL' with an argument list of type '(Bool, String?)'
Method using old fashion Boolean which is in fact UInt8
. Method also use CFString
and not String
.
Easy solution is following:
policy = SecPolicyCreateSSL(1, domain as CFString)
More sophisticated solution is use extension for Bool
:
extension Bool {
var booleanValue : Boolean {
return self ? 1 : 0
}
init(booleanValue : Boolean) {
self = booleanValue == 0 ? false : true
}
}
Then you can use:
policy = SecPolicyCreateSSL(true.booleanValue, domain as CFString)
Related Topics
How Do People Deal with Iterating a Swift Struct Value-Type Property
What Determines Whether a Swift 5.5 Task Initializer Runs on the Main Thread
How to Bind Different Associated Values in a Swift Enum to the Same Var
Non-Strong References Not Working in Playground
How to Add Kerning to a Textfield in Swiftui
Compare App Versions After Update Using Decimals Like 2.5.2
Is There a Writetofile Equivalent for Swift 3's 'Data' Type
Getting Dyld_Fatal_Error After Updating to Xcode 6 Beta 4 Using Swift
Moving Node on Top of a Moving Platform
Working with C Strings in Swift, Or: How to Convert Unsafepointer<Cchar> to Cstring
Two Tables on One View in Swift
Swift Map(_:) Extension for Set()
Swift 5.5: Asynchronously Iterating Line-By-Line Through a File
Know When an Iteration Over Array with Async Method Is Finished
How to Create an Array of Functions
Swift Closure Not Setting Variable