我的项目使用Objective-C和Swift代码.当用户登录时,它会为用户首选项调用一组apis,我有一个DataCoordinator.swift类来调度API操作,我从UserDetailViewController.m类调用此类来加载用户首选项.在使用Xcode 9 beta 4将我的代码迁移到Swift 4之前,这种用法正常工作.现在当我登录时,我在DataCoordinator类中给出了这个错误.下面是我的DataCoordinator和Viewcontroller类的示例.
DataCoordinator.swift
import UIKit
@objcMembers
class DataCoordinator: NSObject {
//MARK:- Private
fileprivate var user = myDataStore.sharedInstance().user
fileprivate var preferenceFetchOperations = [FetchOperation]()
fileprivate func scheduleFetchOperation(_ operation:FetchOperation, inFetchOperations operations:inout [FetchOperation]) {
guard operations.index(of: operation) == nil else { return }
operations.append(operation)
}
fileprivate func completeFetchOperation(_ fetchOperation:FetchOperation, withError error:Error?, andCompletionHandler handler:@escaping FetchCompletionHandler) {
func removeOperation(_ operation:FetchOperation, fromOperations operations:inout [FetchOperation]) {
if operations.count > 0 {
operations.remove(at: operations.index(of: fetchOperation)!)
handler(error)
}
}
if preferenceFetchOperations.contains(fetchOperation) {
removeOperation(fetchOperation, fromOperations: &preferenceFetchOperations)
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个包含10个元素的数组,这些元素称为产品,默认排序,这是当前的日志.
for (int i=0;i<products.count; i++)
{
NSLog(@"%@",products[i]);
}
Run Code Online (Sandbox Code Playgroud)
输出:
Product1
Product10
Product2
Product3
Product4
Product5
Product6
Product7
Product8
Product9
Run Code Online (Sandbox Code Playgroud)
我需要按以下顺序对其进行排序:
Product1
Product2
Product3
Product4
Product5
Product6
Product7
Product8
Product9
Product10
Run Code Online (Sandbox Code Playgroud)
我目前的方法是扫描数字并根据它进行排序,我想知道在iOS中是否有任何其他方法或默认方法可以做到这一点,或者我是否必须坚持使用我当前扫描每个元素中的数字的方法然后排序?
新的iPad专业版具有不同的尺寸和分辨率.如果我根据屏幕宽度检查是否正确?我没有升级到Xcode 7.1也没有设备,所以我还没有检查它.这项检查有效吗?
if([UIScreen mainScreen].bounds.size.width>1024)
{
// iPad is an iPad Pro
}
Run Code Online (Sandbox Code Playgroud) 我有一个排序函数,按姓氏对地址簿进行排序,我需要修改此代码,以便它按名字排序.我在哪里需要对此代码进行更改.我知道这是一个简单的改变,但我无法弄清楚.这是按姓氏对联系人列表进行排序的代码
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy
(
kCFAllocatorDefault,
CFArrayGetCount(people),
people
);
CFArraySortValues
(
peopleMutable,
CFRangeMake(0, CFArrayGetCount(peopleMutable)),
(CFComparatorFunction) ABPersonComparePeopleByName,
(void*) ABPersonGetSortOrdering()
);
Run Code Online (Sandbox Code Playgroud) 我从 XCode 7.1 创建了一个 SampleApp.app 文件,并将其转换为 pkg 文件,并使用产品构建命令对其进行签名,并且工作正常。但现在的问题是,当我安装 pkg 时,应用程序在安装后不会自动启动。我是否需要在命令中包含任何其他参数才能使其正常工作?下面是我用来创建和签署 pkg 的命令。
productbuild --component SampleApp.app /Applications SampleApp.pkg
productsign --sign "Developer ID Installer: xxxxx" SampleApp.pkg SampleApp_signed.pkg
Run Code Online (Sandbox Code Playgroud)
我还尝试添加安装后脚本,但这似乎不起作用,我不确定是否是我的脚本或命令的问题
pkgbuild --root SampleApp.app --identifier com.companyname.SampleApp --scripts startup.sh --install-location /Applications/SampleApp.app SampleApp.pkg
productsign --sign "Developer ID Installer: xxxxx" SampleApp.pkg SampleApp_signed.pkg
Run Code Online (Sandbox Code Playgroud)
我的startup.sh文件
#!/bin/bash
open -a /Applications/SampleApp.app
exit 0
Run Code Online (Sandbox Code Playgroud) 我正在使用下面的方法在Swift 3中将textView.typingAttributes前景色设置为红色.
textView.typingAttributes[NSForegroundColorAttributeName] = UIColor.red
Run Code Online (Sandbox Code Playgroud)
现在,我已经向Swift 4迁移了它的显示错误,我尝试如下,但它仍然显示错误.什么是正确的设置方式?
textView.typingAttributes[NSAttributedStringKey.foregroundColor] = UIColor.red
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用自定义UIPopoverPresentationController类来显示弹出窗口.但它崩溃了错误(<UIPopoverPresentationController: 0x7a772950>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.下面是我发生崩溃的按钮单击代码.
- (IBAction)showPopup:(UIButton *)sender {
ViewController *contentViewController = [[ViewController alloc] init];
contentViewController.preferredContentSize = CGSizeMake(200, 200);
contentViewController.modalPresentationStyle = UIModalPresentationPopover;
myPopoverController *popOver = [[myPopoverController alloc]initWithPresentedViewController:contentViewController presentingViewController:self andTintColor:[UIColor lightGrayColor]];
popOver.delegate = self;
popOver.permittedArrowDirections = UIPopoverArrowDirectionUp;
popOver.sourceRect = sender.frame;
popOver.sourceView = self.view;
[self presentViewController:contentViewController animated: YES completion: nil];
}
Run Code Online (Sandbox Code Playgroud)
下面是我的自定义UIPopoverPresentationController的样子示例
myPopoverController.h file
@interface myPopoverController : UIPopoverPresentationController
@property (readonly) UIColor *tintColor;
-(instancetype)initWithPresentedViewController:(UIViewController *)presentedViewController presentingViewController:(UIViewController *)presentingViewController andTintColor:(UIColor *)aTintColor;
@end
myPopoverController.m file …Run Code Online (Sandbox Code Playgroud) exception objective-c subclassing uipresentationcontroller ios9
我在我的 ViewController willAppear 方法中进行 API 调用,直到 API 响应完成我使用这个 showWait 和 hideWait 方法来显示和关闭活动指示器。但我遇到的问题是,在我的 ViewController 中,我有一个带有不同自定义单元格的表格视图,并且假设我在加载过程中一直点击单元格,一旦加载消失,它的所有操作都会被多次调用。下面是我用于显示和隐藏指示器的代码,我尝试将 userInteractionEnabled 设置为 false 但这没有用。此外,尝试了 beginIgnoringInteractionEvents,它在某种程度上有效,但如果你继续点击直到加载器消失,这也会失败。不知道如何从这里开始。任何帮助表示赞赏。
class func showWait() {
DispatchQueue.main.async {
UIApplication.shared.beginIgnoringInteractionEvents()
if let appdelegate = UIApplication.shared.delegate as? AppDelegate,
appdelegate.myIndicatorView == nil {
appdelegate.myIndicatorView = MyIndicatorView(frame: UIScreen.main.bounds)
appdelegate.window?.subviews[0].addSubview(appdelegate.myIndicatorView!)
}
}
}
class func hideWait() {
if let appdelegate = UIApplication.shared.delegate as? AppDelegate,
appdelegate.myIndicatorView != nil {
DispatchQueue.main.async {
appdelegate.myIndicatorView?.removeFromSuperview()
appdelegate.myIndicatorView = nil
UIApplication.shared.endIgnoringInteractionEvents()
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Facebook我的应用程序实现注册/登录.目前我正在关注Facebook developer Facebook开发人员的Login Ui教程
我已经导入了Facebook SDK以下代码也可以
FBLoginView *loginView = [[FBLoginView alloc] init];
[self.view addSubview:loginView];
Run Code Online (Sandbox Code Playgroud)
现在我需要的是
1)将FBLogin按钮更改为我的自定义按钮
2)当登录成功时,我需要捕获用户性别,电子邮件和profileid以存储在服务器中进行注册,并验证用户是否已经登录
3)还需要知道我应该在会话中存储哪些细节以从中获取用户的朋友列表 facebook
如果有人这样做了,请帮助我提供您的指导和源代码.
提前致谢
我有一个NSMutableArray名为_groupCategoryCurrentIds其格式的数据
(
{
id = 2;
name = Fashion;
},
{
id = 5;
name = Leisure;
},
{
id = 14;
name = Clothing;
},
{
id = 17;
name = Sports;
},
{
id = 2;
name = Fashion;
},
{
id = 36;
name = Men;
},
{
id = 34;
name = Woodland;
},
{
id = 30;
name = Accessories;
},
{
id = 4;
name = Entertainment;
},
{
id …Run Code Online (Sandbox Code Playgroud) ios ×7
objective-c ×6
sorting ×2
swift ×2
swift4 ×2
xcode9-beta ×2
crash ×1
exception ×1
facebook ×1
ios11 ×1
ios9 ×1
ipad ×1
iphone ×1
macos ×1
nspredicate ×1
subclassing ×1
swift4.2 ×1
terminal ×1
touch-event ×1
uitextview ×1
xcode ×1
xcode10.1 ×1
xcode7 ×1
xcode7.1 ×1