Trying to convert objective-c to swift and couldnt solve an issue - ios

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()

Related

Argument Labels '(_: RSKImageCropMode:)' do not match any available overloads

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

Conversion error for rangeofcharacterfromset from swift 2.3 to swift 3.0

I am trying to convert my application from swift 2.3 to swift 3.0. I am facing the following issue.
I am trying to check whether a range of character set is found or not. Code works fine in swift 2.3 and when converting it to swift 3.0.
Can some one help me out with this issue.
Thanks in advance.
This code works in playground:
let string = String()
let characterSet = CharacterSet()
let stringSet : String = string as String
stringSet.rangeOfCharacter(from: characterSet.inverted, options: String.CompareOptions.caseInsensitive)
The easiest way to figure out yourself is to retype the method and use code completion.
Alternatively read the documentation

Implementing Methods from Objective C Library with Swift

I am trying to implement the following method in swift:
From the class FLIROneSDKImageReceiverDelegate, which is subclassed inside my ViewController class as so:
class ViewController: UIViewController, FLIROneSDKImageReceiverDelegate,
FLIROneSDKStreamManagerDelegate,
FLIROneSDKImageEditorDelegate{
Note that I have already created a bridging header etc.
In the FLIROneSDKImageReceiverDelegate header file:
- (void) FLIROneSDKDelegateManager:(FLIROneSDKDelegateManager *)delegateManager didReceiveBlendedMSXRGBA8888Image:(NSData *)msxImage imageSize:(CGSize)size;
Am I wrong in thinking that this is the correct way to implement this function?
func FLIROneSDKDelegateManagerdidReceiveBlendedMSXRGBA8888ImageimageSize(delegateManager: FLIROneSDKDelegateManager!, msxImage: NSData, size: CGSize){
Note that FLIROneSDKDelegateManager is a class.
Off the top of my head, but try this:
func FLIROneSDKDelegateManager(delegateManager: FLIROneSDKDelegateManager!, didReceiveBlendedMSXRGBA8888Image msxImage: NSData!, imageSize size: CGSize) {
// method imp
}
#Laxsnor's solution in the comments on the answer by #aaron-wojnowski helped me too, thanks both.
To consolidate:
The problem is a conflict created by the name FLIROneSDKDelegateManager being used as a both a class name and a function name - which seems to be OK in Objective-C but not in Swift.
Replacing the class FLIROneSDKDelegateManager with NSObject in the function parameter seems to solve the problem without side-effects. This has to be done in both the Objective-C protocol header file and the Swift delegate class source file.
NOTE I also found this same solution applied more broadly to Swift-ify the entire FLIROneSDK at https://github.com/jruhym/flirmebaby.
Happy developing for FLIROne on Swift. (I'm new to FLIROne and relatively new to Swift so apologies if my language isn't quite precise enough.)

Using NS_ENUM from Objective-C in Swift

I am using a third party library in my Objective-C project that has an enum defined as:
typedef NS_ENUM(NSUInteger, RJBEvent)
{
RJB_EVENT_OK = 1,
RJB_EVENT_ERROR=2,
RJB_EVENT_START = 4,
};
Then in Objective-C, I can do the following:
[self.rjbLib listenForEvents:(RJB_EVENT_START|RJB_EVENT_OK|RJB_EVENT_ERROR)];
As an exercise to teach myself Swift, I'm porting the app. All's well until I run up against using this enum. There's a ton of info out there about how (or how not to) use enums in Swift, but very little to describe this bitmask-style usage. I've got this, and it compiles, but I'm not receiving the expected event notifications.
let rjbEventsMask : UInt32 = UInt32(RJBEvent.RJB_EVENT_OK.rawValue |
RJBEvent.RJB_EVENT_ERROR.rawValue |
RJBEvent.RJB_EVENT_START.rawValue)
I do see a suggestion on NSHipster that I may need to change the third-party header file to use NS_OPTIONS. I'm going to try that, but changing the developer's provided .h file is a bit dangerous, so it's not my preferred approach.
Any guidance is appreciated.
Thanks!
Rob

CHCSVPaser initialization in swift

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.

Resources