Ensembles in iOS swift - ios

I would like to use Drew McCormack's Ensembles from github to relieve my current iOS/swift/coredata/iCloud induced headache. All of the Ensembles examples are in Objective-C. I have it as a Framework in my project, but being a weekend coder, I can't extrapolate how to use it from the ObjC example code.
Has anyone seen a How-To for Ensembles using swift?
Adding: I have it as a framework, but how do I set it up and have it start Leeching? The Obj-C way is to
//SetupEnsemble
cloudFileSystem=[[CDEICloudFileSystemalloc] initWithUbiquityContainerIdentifier:#"container"];
ensemble=[[CDEPersistentStoreEnsemblealloc]initWithEnsembleIdentifier:#"MainStore" persistentStoreURL:storeURL
managedObjectModelURL:modelURL
cloudFileSystem:cloudFileSystem]; ensemble.delegate=self;
and then Leech
if(!ensemble.isLeeched){
[ensemble leechPersistentStoreWithCompletion:^(NSError *error) {
if (error) NSLog(#"Could not leech to ensemble: %#", error); }];}

The following steps describe how you add ensembles with the iCloud + Dropbox filesystem to your project:
Add a 'Podfile' to your project with this contents:
target :YOUR_TARGET_NAME do
platform :ios, '7.0'
pod "Ensembles", :git => 'https://github.com/drewmccormack/ensembles.git'
pod "Ensembles/Dropbox", :git => 'https://github.com/drewmccormack/ensembles.git'
link_with 'YOUR_TARGET_NAME'
end
Run 'pod install' from your terminal
Create a ObjC bridging header
Add Ensembles (and other frameworks to the bridging header):
#import <Foundation/Foundation.h>
#import <Ensembles/Ensembles.h>
#import "DropboxSDK.h"
#import "CDEDropboxCloudFileSystem.h"
Happy coding:
var ensemble:CDEPersistentStoreEnsemble?
var ensembleFileSystem:CDECloudFileSystem?
ensembleFileSystem = CDEICloudFileSystem(
ubiquityContainerIdentifier: "SOME_CONTAINER",
relativePathToRootInContainer: "STORE_ROOT_PATH"
)
ensemble = CDEPersistentStoreEnsemble(
ensembleIdentifier: "IDENTIFIER",
persistentStoreURL: "STORE_URL",
persistentStoreOptions:nil,
managedObjectModelURL:"MOM_URL",
cloudFileSystem:ensembleFileSystem,
localDataRootDirectoryURL:"DATA_ROOT_URL"
)
e.leechPersistentStoreWithCompletion({ (error:NSError?) -> Void in
// check for error, etc...
})

If you're a weekend coder I would recommend using Apple's CloudKit. It's all in swift, of course. There are are some good tutorials at: https://videos.raywenderlich.com/courses/45-introduction-to-cloudkit/lessons/1

Related

IOS Module not found error when adding Objective-C framework projects using CocoaPods as a module in Swift project

I have scenario where i have couple of SDKs and a test app. Here is the example.
SDKCore - “Objective-C Framework”
SDKUI - “Objective-C Framework”
SDKCore is added as a dependency using Cocoapods pod 'SDKCore', :path => '../SDKCore' and with flag ‘use_frameworks’
SDKUIViewController uses methods from SDKCore. I’m importing like this #import SDKCore;
Code
#import "SDKUIViewController.h"
#import SDKCore;
#interface SDKUIViewController ()
#end
#implementation SDKUIViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[SDKClass hitTest];
self.view.backgroundColor = [UIColor redColor];
}
#end
SDKTestSwift
SDKCore is added as a dependency using Cocoapods pod 'SDKCore', :path => '../SDKCore' and with flag ‘use_frameworks’
SDKUI is added as a dependency using Cocoapods pod 'SDKUI', :path => '../SDKUI' and with flag ‘use_frameworks’
Problem
is when i compile SDKTestSwift I’m getting Module SDKCore not founda compile error on one of the files from SDKUI (See attached)
Really got stuck here. Thanks a lot in advance.
You can download the sample project from here.
Sorry, I actually have misunderstood you from the start, your issue lying in your pod, not project, this happen because you didn't state that the SDKUI depend on SDKCore, thats why you cant use any code from SDKCore
To fix this, simply add s.dependency 'SDKCore' in your SDKUI.podspec and run pod install again, then it works

Pinterest Linker Error when added through CocoaPods

1)I have did all steps given at Pinterest developer site here
2)This is my pod file
# Uncomment this line to define a global platform for your project
platform :ios, ‘7.0’
# Uncomment this line if you're using Swift
# use_frameworks!
target 'xyz.com' do
pod "PinterestSDK", :git => "https://github.com/pinterest/ios-pdk.git"
end
target 'xyz.comTests' do
end
3)When I run without #import "PDKPin.h" & following code
[PDKPin pinWithImageURL:[NSURL URLWithString:imageUrl]
link:[NSURL URLWithString:shareUrl]
suggestedBoardName:#""
note:productName
withSuccess:^
{
NSLog(#"Succesful to pin");
}
andFailure:^(NSError *error)
{
NSLog(#"Failed to pin");
}];
it runs without error
4)But when I add the above code it gives linker error
Edit: I have tried it in blank project it works fine. But I am unable
to figure out what all the dependencies still there in old project.
Start Fresh
Use Xcode 7.1+, create a new project, run pod install:
target 'SO-34633492' do
pod "PinterestSDK", :git => "https://github.com/pinterest/ios-pdk.git"
end
You probably have inconsistencies in your existing project ; while figuring out what is wrong may be enlightening, may I suggest starting on a clean slate.
Must include headers
You cannot compile your .m without including #import <PDKPin.h>:
~/SO-34633492/SO-34633492/ViewController.m:21:6: Use of undeclared identifier 'PDKPin'
This does work:
#import <PDKPin.h>
NSString * imageUrl = #"";
NSString * shareUrl = #"";
NSString * productName = #"";
[PDKPin pinWithImageURL:[NSURL URLWithString:imageUrl]
link:[NSURL URLWithString:shareUrl]
suggestedBoardName:#""
note:productName
withSuccess:^
{
NSLog(#"Succesful to pin");
}
andFailure:^(NSError *error)
{
NSLog(#"Failed to pin");
}];
Things that may have gone wrong
Compare your projects: https://stackoverflow.com/a/2889730/218152
Delete Derived data: https://stackoverflow.com/a/32859942/218152
Library not found: https://stackoverflow.com/a/31419234/218152
Configuration error: https://stackoverflow.com/a/33509278/218152
Read more: https://stackoverflow.com/search?q=user%3A218152+cocoapod
After a long search & tries
I have found the following solution
I have changed the target's build settings in
the other linker flags section.
I have added the flag $(inherited) in other linker flags

Using UIActivityIndicator-for-SDWebImage with Swift

I'm using SDWebImage and I would like to add a loading indicator. I found the UIActivityIndicator-for-SDWebImage library, and I have tried to add it to my Swift project by adding this:
#import "UIImageView+UIActivityIndicatorForSDWebImage.h"
to my bridging header. For some reason I still can't access the extra parameter usingActivityIndicatorStyle when setting image URLs.
Anyone have any idea what I'm doing wrong? I've tried removing the .m and .h files and re-adding them, but it didn't help.
Add "use_frameworks!" in the Podfile
use_frameworks!
target '<YOUR TARGET>' do
.........
pod 'UIActivityIndicator-for-SDWebImage'
.........
end
In "Pods -> UIActivityIndicator-for-SDWebImage -> UIImageView+UIActivityIndicatorForSDWebImage.h" replace:
#import "UIImageView+WebCache.h"
#import "SDImageCache.h"
With:
#import <SDWebImage/UIImageView+WebCache.h>
#import <SDWebImage/SDImageCache.h>
In "AppDelegate.swift" add
import UIActivityIndicator_for_SDWebImage
That's all.
P.S. You should correct Pods because author of UIActivityIndicator-for-SDWebImage wrote in description: "... I really don't want to keep this repo updated ...", and he really doesn't do it.
Swift 3 & SDWebImage 4.0.0
This will do the trick, try this code
let urlString = URL(string: "Your image URL")
yourImageView.sd_setIndicatorStyle(.gray)
yourImageView.sd_setShowActivityIndicatorView(true)
yourImageView.sd_setImage(with: urlString) { (loadedImage, error, cacheType, url) in
yourImageView.sd_removeActivityIndicator()
if error != nil {
print("Error code: \(error!.localizedDescription)")
} else {
yourImageView.image = loadedImage
}
}
The answer above works
Follow this issue https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebImage/pull/28
You will find a fork which has made this update
https://github.com/masterfego/UIActivityIndicator-for-SDWebImage
I forked it too,
https://github.com/useeless37/UIActivityIndicator-for-SDWebImage
then in your pod file
pod 'UIActivityIndicator-for-SDWebImage', :git => 'https://github.com/useeless37/UIActivityIndicator-for-SDWebImage.git'

Bridge Google Drive API to Swift

From a previously removed post:
I am struggling to get the Google Drive API to work with Swift, and hoping someone has a suggestion. Here is where I am at so far: I have the Google Drive API installed and working in an Objective-C ...
I am trying to reproduce this example from Google in Swift, but import GTLDrive returns an error in Xcode:
No such module 'GTLDrive.
I am unable to use GTLServiceDrive from the Swift classes.
Which combination of CocoaPod + bridging header should I use?
You need 3 things:
(1) Well formed Podfile
platform :ios, '8.0'
target 'GoogleDrive' do
pod 'Google-API-Client/Drive', '~> 1.0'
end
(2) Expose Google API through the bridging headers
#import "GTMOAuth2ViewControllerTouch.h"
#import "GTLDrive.h"
(3) No reference GTLDrive required in the Swift client class
override func viewDidLoad() {
super.viewDidLoad()
// ...
let service:GTLServiceDrive = GTLServiceDrive()
service.authorizer = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName("Drive API",
clientID: "YOUR_CLIENT_ID_HERE",
clientSecret: "YOUR_CLIENT_SECRET_HERE")
// ...
}
I just ran into that now in XCode 7.3, and fixed it with the following in the bridging header:
#import <GoogleAPIClient/GTLDrive.h>
Also, if you need the authentication portion:
#import <GTMOAuth2/GTMOAuth2ViewControllerTouch.h>
I threw away Google API Objective C library from Swift altogether and created an interim solution: https://github.com/metaprgmr/GoogleApiProxyForSwift. Incidentally, I used Google Drive as a guinnea pig, where you can find experiments at close to the end of its YouTube presentation. Check it out.

Failed to recognize AWSDynamoDB with XCode 7.0 Beta, iOS 8.3, and aws-ios-sdk-2.2.0

I am matching guides for using AWSDynamoDB in a test project using Swift 2 in XCode 7.0 Beta. I am required to use that platform instead of the previous stable one and make it work.
I am using the next links:
https://docs.aws.amazon.com/mobile/sdkforios/developerguide/setup.html
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LoadData_Java.html
Best way to make Amazon AWS DynamoDB queries using Swift?
I already made it work for reading and writing text files and images to an S3 Bucket, but now that I am trying to use DynamoDB service something might be missing.
Here is my Podfile contents:
# Uncomment this line to define a global platform for your project
platform :ios, '8.3'
target 'AWSSDKTest' do
source 'https://github.com/CocoaPods/Specs.git'
pod 'AWSCore'
pod 'AWSAutoScaling'
pod 'AWSCloudWatch'
pod 'AWSDynamoDB'
pod 'AWSEC2'
pod 'AWSElasticLoadBalancing'
pod 'AWSKinesis'
pod 'AWSLambda'
pod 'AWSMachineLearning'
pod 'AWSMobileAnalytics'
pod 'AWSS3'
pod 'AWSSES'
pod 'AWSSimpleDB'
pod 'AWSSNS'
pod 'AWSSQS'
pod 'AWSCognito'
end
target 'AWSSDKTestTests' do
end
I had to delete Podfile.lock and Pods folder, deleted Configuration Sets in Project->Info->Configurations, and installed pods again.
Here is my bridging.h file:
#ifndef AWSSDKTest_bridging_h
#define AWSSDKTest_bridging_h
#endif
#import <AWSCore/AWSCore.h>
#import <AWSS3/AWSS3.h>
#import <AWSDynamoDB/AWSDynamoDB.h>
#import <AWSSQS/AWSSQS.h>
#import <AWSSNS/AWSSNS.h>
#import <AWSCognito/AWSCognito.h>
I downloaded the aws-ios-sdk-2.2.0.zip file, unzipped and added to Frameworks all the AWS frameworks.
I am trying to use AWSDynamoDBModel, here is a swift file for implementing the Upload Sample Items Example for using DynamoDB Mapper:
import Foundation
class Forum : AWSDynamoDBModel, AWSDynamoDBModeling {
var name : String = ""
var category : String = ""
var threads : Int = 0
var messages : Int = 0
var views : Int = 0
// override init!() { super.init() }
required init!(coder: NSCoder!) {
fatalError("init(coder:) has not been implemented")
}
class func dynamoDBTableName() -> String! {
return "Demo"
}
class func hashKeyAttribute() -> String! {
return "email"
}
class func rangeKeyAttribute() -> String! {
return "date"
}
/*
override init(dictionary dictionaryValue: [NSObject : AnyObject]!, error: NSErrorPointer) {
super.init(dictionary: dictionaryValue, error: error)
}
override func isEqual(anObject: AnyObject?) -> Bool {
return super.isEqual(anObject)
}
*/
}
I had to comment the lines that caused error because those might be fixed. The errors mentioned that those functions couldnt be overridden and that super.init couldnt be called inside a root method.
After cleaning and building again, the error is at the class declaration line
class Forum : AWSDynamoDBModel, AWSDynamoDBModeling {
The error says: Use of undeclared type 'AWSDynamoDBModel'
If I try writing other AWSDynamoDB classes they don't appear in the list of suggestions and then cause the same error.
Additionally I want to mention that in the developer's guide setup (first link above) the 4th point of the Getting Started with Swift section says: "Import the AWSCore header in the application delegate":
#import <AWSCore/AWSCore.h>
Than can't be done, only in the bridging.h file which is mentioned in the 2nd point.
My first request of assistance is in fixing the error mentioned and making the project recognize the AWSDynamoDB framework.
Then I request your help for any observation about this merge of different tutorials, also any other online tutorial or guide that is more clear than those mentioned.
In case you are using CocoaPods (0.36) with "use_frameworks!", this answer might solve your problem:
"Normally when you’re importing Objective-C code into Swift, you do so by including the header of the file containing that code in the “Bridging Header” for your project. And that is indeed how you include code from a static library (which your pods used to be.)
But it is not how your import Objective-C code from a Framework. To do that you simply type…
import Framework
…inside your Swift file that’s using the Objective-C class (where “Framework” is the name of the actual Framework containing the class.)"
Source here: http://rogueleaderr.com/post/115372471213/unresolved-identifier-in-swift-when-importing
I think the problem is not related to Xcode7Beta, but the installation process of your project. (My sample DynamoDB project runs fine under Xcode7Beta.)
If you installed the AWS Mobile SDK via cocoapods, you neither have to worry about the bridging file nor need to download aws-ios-sdk-2.2.0.zip file since cocoapods already did everything for you.
My suggestion would be:
clean your project, remove all aws related frameworks, bridging files that you manually added,delete Podfile.lock and Pods folder and AWSSDKTest.xcworkspace file, and the re integrate pods by running "pod install"
Open your project using Xcode 6.4, confirm it can be built and run successfully under Xcode 6.
If everything looks good via Xcode 6, reopen it via Xcode7Beta, If it failed to compile, please post the error output so I can take a look.
Thanks

Resources