Which keys do I need for CNContactFormatter? - formatting

I'm trying to format a contact's name using the new CNContactFormatter. It looks like, I didn't fetch all needed name properties of the contact.
Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'A property was not requested when contact was fetched.'
Does anyone know which ones are required? I tried fetching the following amongst a few others with no luck:
CNContactNamePrefixKey,
CNContactGivenNameKey,
CNContactFamilyNameKey,
CNContactMiddleNameKey,
CNContactPreviousFamilyNameKey,
CNContactNameSuffixKey,
CNContactNicknameKey,
CNContactPhoneticGivenNameKey,
CNContactPhoneticMiddleNameKey,
CNContactPhoneticFamilyNameKey,
CNContactOrganizationNameKey,
CNContactDepartmentNameKey,
CNContactJobTitleKey,
Neither the CNContactFomatter Class Reference nor the fetching method's documentation give any clue.
Thanks!

I found this in the WWDC Session 223 (starting at slide 74) and this worked for me when I was having the same problem. Use CNContactFormatter.descriptorForRequiredKeysForStyle... in the contact selection call. Example:
let contactStore = CNContactStore()
let predicate = CNContact.predicateForContactsMatchingName("John")
let foundContacts = try contactStore.unifiedContactsMatchingPredicate(predicate, keysToFetch: [CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName)]
for contact in foundContacts {
print(CNContactFormatter.stringFromContact(contact, style: .FullName))
}

class func descriptorForRequiredKeys()
Use to fetch all contact keys required to create vCard data from a contact.
https://developer.apple.com/reference/contacts/cncontactvcardserialization
Example:
let containerResults = try contactStore.unifiedContacts(matching: fetchPredicate, keysToFetch:[CNContactVCardSerialization.descriptorForRequiredKeys()])

Related

How can I change the "key" name from an action field in Zapier (Scripting) with the KEY_pre_write method?

I was wondering how I can change the key of an action field through scripting in Zapier. I know I need to use KEY_pre_write to change an element before I send the request but how can I call the specific action field and change the key name in something else?
Zapier scripting image
The key name is currently "type" but I want to change it for instance to "type1".
Thanks in advance.
Fixed it myself btw, maybe for someone who needs to know.
'use strict';
var Zap = {
CompanyAdd_pre_write: function(bundle) {
var actionfields = bundle.action_fields;
var stringify = JSON.stringify(actionfields);
var body = stringify.replace("type1", "type"); // renaming key
bundle.request.data = body;
console.log(actionfields);
return bundle.request;
}
};
David here, from the Zapier Platform team.
key is set by the key of the action itself. See here:
Those would be action_pre_write, broken_js_pre_write, etc. Feel free to tweak these for a private app, but note that it'll break any existing zaps that use that action.
​Let me know if you've got any other questions!

How to add an User Content through Sensenet Client?

I want to add an User Content of Sensenet from a client which developed by .NET.
Please give me a solution.
Thanks so much.
You should be able to create users the same way as any other content, by providing the parent, the content type name and a few mandatory fields.
The example below assumes that you already initialized the client, you have the /Root/IMS/MyDomain/MyOrgUnit in your repo and there is no existing user there with the same name.
var user = Content.CreateNew("/Root/IMS/MyDomain/MyOrgUnit", "User", "johnsmith");
user["LoginName"] = "johnsmith"; // best practice: same as the content name in the line above
user["Password"] = "123456789";
user["FullName"] = "John Smith";
user["Email"] = "johnsmith#example.com"; // this has to be unique under the domain
user["Enabled"] = true; // to let the user actually log in
await user.SaveAsync();
Let us know if you encounter any errors.

Ambigious reference to member 'create' Swift and ObjectiveRecord

I'm using ObjectiveRecord library. There's no problem when use this with Objective-C. But when I use with Swift, maybe it's new to some one, there's problem when I want to create a record to database.
I use Birdging-Header.h with code as below
#import "ObjectiveRecord.h"
When I call as below
var category:Category = Category.create()
category.pkId = 1
category.title = "This is a sample"
At the first line the is error "Ambigious reference to member 'create'".
Is there anyone experience with this error. Please give me advice! Thanks a lot !
Edited:
Detail of Category class
class Category: NSManagedObject {
var pkId: NSInteger?
var title: NSString?
var img: NSString?
}
This is Category class.
Edited:
I resolved the problem above, but now I'm facing another problem. This is how to resolve the above
let category:Category = Category.create() as! Category
Now it throw error as below
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an entity named 'Shopping.Category' in this model.'
Is there anyone know how to solve this ?

Angular dynamic factory

I'm trying to use a single controller to list multiple similar collections so I can call different templates with the same controller. In fact, right now I have 6 controllers for listing and another 6 for forms but they're all duplicates.
I've made a non-functional plunker just to show how I intend it to work. I've avoided declaring routeProviders because knowing it wouldn't work I tried to make it as straight to the point as I could.
http://plnkr.co/edit/d06PcrJS5newhrmNy6EJ?p=preview
I've seen on stackoverflow how to declare a class with a dynamic name:
var str = "MyClass";
var obj = new window[str];
But as I have not been able to find where it's stored I'm not able to retrieve it.
Does anyone have a hint on how to do this?
You can use Angular's injector to return the service instance you want. For example:
app.controller('NodeListCtrl', function($scope, $location, $injector) {
var modelName = $location.path().split("/")[1];
$scope.modelName = modelName.charAt(0).toUpperCase() + modelName.slice(1);
$scope.nodes = $injector.get($scope.modelName).query();
});
Note: Don't forget to add the $injector to the controller's function signature.
jsfiddle: http://jsfiddle.net/bmleite/Mvk2y/

How to get an object from a _ref

I apologize if this is a stupid/newb question, but when a Rally query result is returned with a _ref (using the Javascript SDK 1.32), is there a way to directly get the object associated with the _ref?
I see that I can use getRefFromTypeAndObjectId to get the type and the object ID, and then query on that type and object ID to get the object, however I wondered if there was something like getObjectFromRef or some other such way to more directly get back the object associated with the reference.
Excellent question. The getRallyObject method on RallyDataSource should do what you need.
var ref = '/defect/12345.js';
rallyDataSource.getRallyObject(ref, function(result) {
//got it
var name = result.Name;
}, function(response) {
//oh noes... errors
var errors = response.Errors;
});
In SDK 2.0 you use the load method of a data model to read a specific object. Check out this example: http://developer.help.rallydev.com/apps/2.0p5/doc/#!/guide/appsdk_20_data_models