I'm developing iOS app that handles .csv file with CHCSVParser in swift.
in Objective-C, the initialization code goes like this.
CHCSVParser *p = [[CHCSVParser alloc] initWithContentsOfCSVFile:[inputFileURL path]
so in swift, I think it goes like
var p = CHCSVParser()
p.initWithContentsOfCSVFile(path)
but this code leads error "CHCSVParser does not have a member named 'initWithContentsOfCSVFile'".
BridgingHeader file works fine.
func parserDidBeginDocument(parser: CHCSVParser)
this delegation method successfully calld after p.parse() .
Does anyone please help me? What should I do?
Any advice appreciated. Thanks in advance.
Swift does an automatic conversion of Objective-C constructors and removes "initWith". So in Swift, it is like this:
var p = CHCSVParser(contentsOfCSVURL: path)
In cases such as this, I recommend just typing the first part:
var p = CHCSVParser(
an then taking a look at what Xcode autocomplete suggests.
Related
I'm trying to incorporate AudioKit 4.0.3 (latest) into an existing iOS ViewController that's written in Objective C. I am having trouble initializing and using the AKFrequencyTracker class, even though other classes work fine (e.g. AKOscillator and AKMicrophone).
I added the following code to the ViewController viewDidLoad method in the Objective C example that came with it:
AKMicrophone *mic;
mic = [[AKMicrophone alloc] init];
AKFrequencyTracker *tracker;
tracker = [[AKFrequencyTracker alloc] init:mic hopSize:512.0 peakCount:20.0];
But I see an "No visible #interface for 'AKFrequencyTracker'" error in Xcode next to the last line.
It doesn't appear there are any init methods for AKFrequencyTracker. Any help would be greatly appreciated!
Due to a change with Swift 4 we need to explicitly add #objc to the init methods and forgot to do so with AKFrequencyTracker. I just fixed it in this commit:
https://github.com/AudioKit/AudioKit/commit/e9328d4aa8d76d0cae31eeb33b232abebd571d6e
I'm trying to use RSKImageCropper library in swift (Library written in Objective-C).
I encounter the below error in my ViewController.swift file (see image).
Could someone please suggest how I could resolve this issue ?
You are too close to solved this you need to combine your comment code and current error getting code. So you need to initialized RSKImageCropViewController like this way.
let imageCropVC = RSKImageCropViewController(image: image, cropMode: .circle)
/access the imageCropVC
I am trying to convert an objective-c project to swift2
typedef void (^PDFCMapParserHandler)(NSArray *lines);
can someone help?
Whenever I want to convert set of codes from ObjC to Swift, I use this
link which is much easier than banging my head.
To simply answer your question:
var PDFCMapParserHandler or var PDFCMapParserHandler = NSArray()
Currently I am trying to accomplish with Cocos2d-swift+SpriteBuilder and their tutorial provided there
I am trying to do this not in Objective-C but in Swift. So during the tutorial I have faced with the issue when Xcode can't find CCBReader.
As I can see from the project structure, it is in place. The place where I stuck is:
var ball: CCNode = CCBReader.load("Bird")
In the tutorial this line looks like:
CCNode *ball = [CCBReader load:#"Bird"];
The main problem is that I can't get access to the CCBReader while it presents in the libs.
Could someone help me with this please?
This issue was fixed by Cocos2d-Swift 3.4beta + SpriteBuilder 1.4.
http://forum.spritebuilder.com/t/spritebuilder-1-4-beta-release/2573
I am trying to declare a function in my .h file that looks like this:
-(*NSString) encode: (NSString*) unencodedString;
and I get a syntax error:
expected a type
Here is my .m header for this function:
- (NSString*)encode: (NSString*) unencodedString
and here is how I am trying to call it:
EncodingUtil *encode_object = [[EncodingUtil alloc] init];
NSString *encoded_company_name = [encode_object encode: name];
Could someone please help me understand what I am doing wrong and how to fix it?
Thanks!
Your return type says (*NSString). That's completely backwards. You want (NSString*).
Of course it does (and you should really learn C first, you'll get lost in Obj-C if you don't even know how to declare a pointer type!). What you presumably wanted to write is
- (NSString *)encode:(NSString *)unencodedString;