Cannot Invoke "+=" with an Argument List of Type (Int, @Value Int)

Cannot invoke += with an argument list of type (Int, @value Int)

let creates an immutable value. You need to use var, like:

func computeTotal()-> Int{
var total = 0
for transaction in transactions{
//get the amounts of each and sum all of them up
total += transaction.amount
}
return total
}

Swift cannot invoke '*' with an argument list of type '(Int, Int)'

The compiler error is misleading.

The real issue is that you missed the declaration of the function return type, so the compiler infers Void and it gets confused when tries (and fails) to find a suitable overloading for * that returns Void.

Change your function to

func timesByHundred(d: Int) -> Int {
return d * 100
}

Cannot invoke 'swapAt' with an argument list of type '(Int, Int)'

Actually no, MutableCollection.swapAt is not defined to take two Int, it is defined in terms of Index of the MutableCollection:

swapAt(Self.Index, Self.Index)

Therefore you cannot just use Int unless you add

Index == Int

constraint to your declaration, making it:

extension MutableCollection where Self: BidirectionalCollection, Element: Equatable, Index == Int {
mutating func moveRight(_ value: Element){
for i in (0..<self.count) {
if (self[self.index(self.startIndex, offsetBy: i)] == value){
swapAt(0, 5)
}
}
}
}

If you don't want to limit yourself to integer indices, you should start by replacing iteration from 0 ..< count by iteration over indices:

for i in indices {
if (self[i] == value) {
// do swap
...
}
}

cannot invoke 'setScore' with an argument list of type '(Int)'

I’m not sure what are you exactly trying to do but I believe you want to pass data from one WKInterfaceController to other WKInterfaceController, so you can use the context:

self.presentControllerWithName("scorePage", context: countNumber)

Once you are in the receiver WKInterfaceController you should receive the countNumber overriding the awakeWithContext: func (the context var should have the countNumber value now) and then you can set the score:
self.setScore(context)

PS don't forget to "cast" the context value from AnyObject to int

Example using Obj-C and an NSNumber instead of int:

In the origin class:

[self pushControllerWithName:@"scorePage" context:countNumber];

in the destination class:

- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];

if ([context isKindOfClass:[NSNumber class]]) {
NSNumber *num = (NSNumber *)context;
[self setScore:num];
}

}

Cannot invoke 'CGRect.Type.init' with an argument list of type '(x: Int, y: Int, width: Float, height: Float)'

CGRect.init has three different versions, for the three types of arguments it accepts - Int, Double, and CGFloat. Whatever values you're passing into x, y, width, and height must be the same type. To fix this you might try casting your values to Double by wrapping them in Double().


Regarding your comment, there's no version of CGRect.init() that takes Float parameters. Cast your Floats to Double and it should work.

Cannot invoke 'filter' with an argument list of type '((_) - _)'

You can get that error if you didn't make ScriptRunner conform to Equatable:

class ScriptRunner : Equatable {
// the rest of your implementation here
}

func ==(lhs: ScriptRunner, rhs: ScriptRunner) -> Bool {
return ... // change this to whatever test that satisfies that lhs and rhs are equal
}

Cannot invoke 'UIImage' with an argument list of type '(Int, @escaping () - ())' error while using didFinishPickingMediaWithInfo method

You missed the let keyword when getting an image from scaleImage function

Change your code like below to working it

if let selectedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {

if let scaledPhoto = selectedImage.scaleImage(100) {

print(scaledPhoto)
activityIndicatorOutlet.startAnimating()
dismiss(animated: true, completion: {
//recognize the image
})
}
}

Cannot invoke initializer for type CGFloat with an argument list of type 'String'

The error is clearly saying that CGFloat doesn't have initializer that accept String as argument. You can use wrapped around like first convert String to Float and then convert Float to CGFloat.

public func barChartView(_ barChartView: JBBarChartView!, heightForBarViewAt index: UInt) -> CGFloat {

if let value = Float(chartData[Int(index)]) {
return CGFloat(value)
}
return 0
}

Note: Be sure that this String have number as value otherwise it will return 0 for height.

Set default value and type for parameter

My code works for any input type of pk: integer, string with integer, string without integer

import re
def intCheck(pk):
contains_number = bool(re.search(r'\d', pk))
if contains_number:
return int(re.search(r'\d+', pk).group())
else:
return 0

def profile(request, pk=0):
pk = intCheck(pk)
print(request + " " + str(pk))

profile('request', "232")
profile('request', 123)
profile('request', "no number")

Output:

request 232
request 123
request 0

How to check if an int is a null

An int is not null, it may be 0 if not initialized.

If you want an integer to be able to be null, you need to use Integer instead of int.

Integer id;
String name;

public Integer getId() { return id; }

Besides, the statement if(person.equals(null)) can't be true because if person is null, then a NullPointerException will be thrown. So the correct expression is if (person == null)



Related Topics



Leave a reply



Submit