我有两个数组:
fruitsArray = ["apple", "mango", "blueberry", "orange"]
vegArray = ["tomato", "potato", "mango", "blueberry"]
Run Code Online (Sandbox Code Playgroud)
如何获得这两个数组中的常用项列表
ouptput = ["mango", "blueberry"]
Run Code Online (Sandbox Code Playgroud)
我无法使用,if contains(array, string)因为我想比较2个数组.
现在我正在使用此代码从手机中获取联系人:
var addressBookReff: ABAddressBookRef = ABAddressBookCreateWithOptions(nil, nil).takeRetainedValue()
let people:NSArray = ABAddressBookCopyArrayOfAllPeople(addressBookReff).takeRetainedValue()
for person in people{
if let name:String = ABRecordCopyValue(person, kABPersonFirstNameProperty)?.takeRetainedValue() as? String {
let numbers:ABMultiValue = ABRecordCopyValue(person, kABPersonPhoneProperty).takeRetainedValue()
if let number:String = ABMultiValueCopyValueAtIndex(numbers,0)?.takeRetainedValue() as? String {
self.arrOfDictContacts.addObject(["\(name)":"\(number)"])
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我kABPersonFirstNameProperty用来获得名字.
我想得到联系人的全名!!!
如果我使用,kABPersonCompositeNameFormatFirstNameFirst那么我会得到错误Int is not convertible toABPropertyId
请原谅我如果这个问题很简单并有很多答案,我可以找到任何一个为我工作,因为我不想要额外的功能.
那么如何获取全名并将其添加到字典中
arrOfDictContacts呢?
我有一组存储在数组中的字符串.
stringArray = [Aruna, Bala, Chitra, Divya, Fatima]
Run Code Online (Sandbox Code Playgroud)
我想得到所有字符串的第一个字母并将其存储在一个数组中.喜欢:letterArray = [A, B, C, D, F]
注意:它们不在引号" - "内
这个问题与我的另一个问题类似
我有2个数组:
fruitsArray = ["apple", "mango", "blueberry", "orange"]
vegArray = ["tomato", "potato", "mango", "blueberry"]
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到fruitsArray比较的不常见元素vegArray
Expected Output = ["apple", orange]
Run Code Online (Sandbox Code Playgroud) 我知道在这个简单的问题上传递了很多问题,但我仍然无法得到一个明确的想法.
这就是我想要的:
SelectedDateString = "19-08-2015 09:00 AM"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy HH:mm a"
dateFormatter.timeZone = NSTimeZone();
let SelectedUTCDate = dateFormatter.dateFromString(SelectedDateString)!
println("SelectedLocalDate = \(SelectedLocalDate)")
// OUTPUT: SelectedLocalDate = 2015-08-18 18:30:00 +0000
Run Code Online (Sandbox Code Playgroud)
如果我不使用TimeZone:
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy HH:mm a"
// dateFormatter.timeZone = NSTimeZone();
let SelectedUTCDate = dateFormatter.dateFromString(SelectedDateString)!
println("SelectedLocalDate = \(SelectedLocalDate)")
//OUTPUT: SelectedLocalDate = 2015-08-18 19:26:00 +0000
Run Code Online (Sandbox Code Playgroud)
为什么时间和日期有变化?我想要的是:
//OUTPUT: SelectedLocalDate = 2015-08-19 09:00:00 +0000
Run Code Online (Sandbox Code Playgroud)
另外,我想将本地日期转换为精确的UTC日期
//Like this: SelectedUTCDate = 2015-08-19 03:30:00
inputString = "19-08-2015 10:45 am" // …Run Code Online (Sandbox Code Playgroud) 我正在尝试加载我的应用程序的联系人.它在模拟器中工作正常.但在iPhone中崩溃.我正在使用的代码:
func getContactNames()
{
let allContacts = ABAddressBookCopyArrayOfAllPeople(addressBookRef).takeRetainedValue() as Array
for record in allContacts {
let currentContact: ABRecordRef = record
let currentContactName = ABRecordCopyCompositeName(currentContact).takeRetainedValue() as String
if(currentContactName != "") {
println("found \(currentContactName).")
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个功能是正确的,在获得几个联系后,应用程序崩溃与日志:
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
Run Code Online (Sandbox Code Playgroud)
我认为这是由于姓名中的联系人,如果我尝试获取电话号码,它工作正常..我可以看到所有的电话号码,但如果是姓名,我可以看到大约350个联系人然后应用程序崩溃.
知道如何解决这个问题吗?
我是node.js的新手,我必须解决它中的错误.我试图通过以下服务更新组成员,每当我尝试调用此API时,我都会收到错误消息
错误:已调用回调.
我的代码是:
'app.post('/api/updateGroup/:group_id', function (req, res) {
var checkGroup = Group.findOne({'_id': req.params.group_id}).exec();
checkGroup.addBack(function( err , existingGroup ) {
if ( err ) {
res.json({'message' : err });
}else if( existingGroup ){
Group.findOne({ '_id': req.params.group_id })
.execQ()
.then(function(existingUser) {
var friendphoneNumber = req.body.friendphoneNumber.split(',');
var friends = [];
console.log('existingUser', friendphoneNumber);
async.each(friendphoneNumber, function(phonenum, callback) {
var phonenum = phonenum.split("\'")[0];
console.log('phonenum', phonenum);
User.findOne({
'phoneNumber': phonenum
})
.execQ()
.then(function(existingFriend) {
if(existingFriend === null) {
friends.push({
'details': {
'phoneNumber': phonenum
}
});
callback();
} else …Run Code Online (Sandbox Code Playgroud) 我有我的班级名称和朋友名称。
我没有 objectId
从 SWIFT 在 Parse 中删除它的代码是什么?
在 ObjC 中,它类似于:
PFObject *object = [PFObject objectWithoutDataWithClassName:@"invFriend"
objectId:@"abcd"];
[object deleteEventually];
Run Code Online (Sandbox Code Playgroud)
我怎么能在没有 objectId 的情况下从 swift 做到这一点?
我有一个数组 objectIds = ["LlbAXkqOL4", "v7lSgUunbR"]
如果我只有一个对象id,那么我可以使用,
query.getObjectInBackgroundWithId("A2332xsdas2")
由于我有很多objectIds,我遵循以下代码:
let userQuery = PFUser.query()
userQuery?.whereKey("username", equalTo: self.user!.username!)
userQuery?.findObjectsInBackgroundWithBlock {
(object, error) -> Void in
if object != nil
{
for messageObject in object! {
self.importedArray = ((messageObject as! PFObject)["AllEventsId"] as? [String]!)!
println("importedArray = \(self.importedArray)")
}
}
}
var query:PFQuery = PFQuery(className: "Events")
query.whereKey("objectId", containedIn: self.importedArray)
query.whereKey("EventSTDTime", greaterThan: zDate)
query.findObjectsInBackgroundWithBlock {
(object, error) -> Void in
if object != nil
{
println(objects)
}
}
Run Code Online (Sandbox Code Playgroud)
但是这个方法不起作用,因为它获取了类下的所有id Events
swift ×8
ios ×7
arrays ×2
contacts ×1
iphone ×1
javascript ×1
jquery ×1
node.js ×1
nsarray ×1
nstimezone ×1