Reputation: 21
Could anybody suggest where I'm going wrong?
Upvotes: 0
Views: 5384
Reputation: 11666
a more elaborated question. first a quick response:
You cannot call swift plain function from objC. You can call methods but not plain f.
see below:
// swift class:
@objc class Klass: NSObject {
var a = 100
@objc public func F1()->String{
return "F1"
}
@objc public func F2()->NSString{
return "f2"
}
}
func myF()->String{
return "FFF"
}
func myG()->NSString{
return "GGG"
}
in objC:
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
Klass* k = [Klass new];
NSString * s1 = [k F1];
NSString * s2 = [k F2];
s1 = k.F1;
s2 = k.F2;
NSString * sf = myF(); // ERROR! ... Implicit conversion of 'int' to 'NSString *' is disallowed with ARC
NSString * sg = myG(); // ERROR! " " "
}
If you add a plain C code (adding includes and so on...)
//file:plainFunctions.c
#include "plainFunctions.h"
int myN()
{
return 100;
}
You can call:
- (void)viewDidLoad {
[super viewDidLoad];
int n = myN();
}
or even:
//h:
char * myC(void);
// objC:
NSString * fromC = [NSString stringWithCString:myC() encoding: NSUTF8StringEncoding];
Upvotes: 2
Reputation: 2601
Beware the comma operator. That the message says ... disallowed with ARC
is a red herring, the issue here is you're assigning a number to an NSString*
.
It's not entirely clear from your screenshot, which I summarise here:
NSString *currurl = (@"https://some-string-%d", 'abcd');
.. where it looks like you're trying to compose an NSString*
.
However the compiler is evaluating an expression comprising an NSString*
, the comma-operator and a character, where the result is the right hand operand of that comma operator. So it is trying to assign abcd
to currurl
.
Remember that characters are integer types in C based languages (same in Java), hence the complaint Implicit conversion of 'int' to 'NSString *'
Upvotes: 0
Reputation: 157
Try writing curl url like this :-
NSString* curlURL = [NSString stringWithFormat:@"https://api.500px.com/v1/photos?.....rpp=20&page=%d", 123];
Hope given string format helps you.. Thanks
Upvotes: 3