Tag: swift

How to use Swift App + (Swift Framework + Objective C static Framework) without warnings

What I am trying to do: Create a swift dynamic framework – Say SwiftDemo.framework Swift.framework depends upon an external Objective-C static framework (No source code available) – Say ObjCDemo.framework. This framework has it’s module file and placed inside ObjCDemo.framework/Modules/module.modulemap Put this SwiftDemo.framework inside an Swift application. Ideally I would want my swift app to be […]

NSOpenPanel in Swift . How to open?

I have this Objective-C Code : – (IBAction)selectFileButtonAction:(id)sender { //create open panel… NSOpenPanel* openPanel = [NSOpenPanel openPanel]; // NSLog(@”Open Panel”); //set restrictions / allowances… [openPanel setAllowsMultipleSelection: NO]; [openPanel setCanChooseDirectories:NO]; [openPanel setCanCreateDirectories:NO]; [openPanel setCanChooseFiles:YES]; //only allow images… [openPanel setAllowedFileTypes:[NSImage imageFileTypes]]; //open panel as sheet on main window… [openPanel beginWithCompletionHandler:^(NSInteger result) { if (result == NSFileHandlingPanelOKButton) { […]

Inter-operability of Swift arrays with C?

How can one pass or copy the data in a C array, such as float foo[1024]; , between C and Swift functions that use fixed size arrays, such as declared by let foo = Float[](count: 1024, repeatedValue: 0.0) ?

Converting UIColor to CGColor in swift

This is the Obj-C code: CGContextSetStrokeColorWithColor(context, [[UIColor lightGrayColor] CGColor]); How do I write it in swift.

Want to add event in google calendar

I want to insert event in google calendar without using any third parties. Please help me if any one know it. Thanks in advance.

Convert Base64 GZipped string Objective-c or Swift

I received a string from a web service like this: CAAAAB+LCAAAAAAABADtvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee++997o7nU4n99//P1xmZAFs9s5K2smeIYCqyB8/fnwfPyJOp/PqTf6u/X8A1v85+wgAAAA= The source string was “EchoText” that compressed with Gzip then converted to Base64. I have to decode Base64 string at first then Unzip that using Gzip. How can I do in Swift (or Objective-C)? Edit: I found a good library for using Gzip: nicklockwood/Gzip […]

Swift 2 Protocol Extensions and Conformance for Objective-C Types

I have a setup like this: @interface Model: NSManagedObject … @end And a Swift protocol like this: @objc protocol Syncable { var uploadURL: String { get } var uploadParams: [String: AnyObject]? { get } func updateSyncState() throws } extension Syncable where Self: NSManagedObject { func updateSyncState() throws { … /* default implementation */ … } […]

In Apple's Documentation for NSObject, what is the idea of the “receiver”?

I’m researching Object-Oriented Programming in Swift and I figured a great place to start would be NSObject, since all objects inherit from this base class. In Apple’s documentation for NSObject, there are areas that refer to a “receiver”. Does “receiver” mean an instance of NSObject?

What am I doing wrong in Swift for calling this Objective-C block/API call?

I’m using RedditKit to integrate Reddit into an app, and in Objective-C I called the API as follows (and it worked fine): [[RKClient sharedClient] signInWithUsername:@”username” password:@”password” completion:^(NSError *error) { RKPagination *pagination = [RKPagination paginationWithLimit:100]; [[RKClient sharedClient] linksInSubredditWithName:subredditSelected pagination:pagination completion:^(NSArray *collection, RKPagination *pagination, NSError *error) { // code that executes on completion }]; }]; Here’s how […]

How to determine if undocumented value for NS_ENUM with Swift 1.2

For instance, following NS_Enum is defined… typedef NS_ENUM(NSInteger, Type) { TypeNone = 0, TypeA = 1, } var x = 2 if let type: Type = Type(rawValue: x) { // Swift 1.2 executes this block. } else { // Previous swift executes this block. } How can I determine if x is defined on NS_ENUM […]