我在启动时传递了一个参数:-D DEBUG它允许我在我的发布应用程序中使用以下内容:
#ifndef DEBUG
/* Some code I only want to be run when using the release app */
#endif
Run Code Online (Sandbox Code Playgroud)
当我运行git status,它显示了我,当添加文件更改-D DEBUG为MyExampleProject.xcodeproj/xcuserdata/myusername.xcuserdatad/xcschemes/MyExampleProject.xcscheme
应使用常用的Xcode .gitignore文件排除哪个.有没有其他方法可以包含符合.gitignore并且不依赖于我的用户帐户的参数xcuserdata?
将我的Core Data架构与提供JSON的远程API同步的最佳方法是什么?目前,我正在循环查看JSON响应中的每个字典,检查核心数据以查看API ID是否存在.
这很好用,但现在要做的就是删除服务器上没有的任何本地对象.以下是我的JSON数据示例:
[
{
"id":1234,
"name":"My first object",
"description":"This is a long string with lots of information"
},
{
"id":1235,
"name":"My second object",
"description":"This is a long string with lots of information"
}
]
Run Code Online (Sandbox Code Playgroud)
目前,我能想到实现这一目标的唯一方法如下:
NSArray *jsonData = // Convert json data to array using NSJSONSerialization
NSInteger fetchedCount = _fetchedResultsController.fetchedObjects.count;
if (fetchedCount != jsonData.count) {
for (int i = 0; i < fetchedCount; i++) {
NSManagedObject *object = [_fetchedResultsController objectAtIndexPath: [NSIndexPath indexPathForItem:i
inSection:0]];
NSNumber *idNumber = object.apiID;
BOOL …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我希望断言已以正确的格式添加通知.我通常会使用依赖注入来执行此操作,但我无法想到测试新UNUserNotificationCenterAPI的方法.
我开始创建一个模拟对象来捕获通知请求:
import Foundation
import UserNotifications
class NotificationCenterMock: UNUserNotificationCenter {
var request: UNNotificationRequest? = nil
override func add(_ request: UNNotificationRequest, withCompletionHandler completionHandler: ((Error?) -> Void)? = nil) {
self.request = request
}
}
Run Code Online (Sandbox Code Playgroud)
但是,UNUserNotificationCenter没有可访问的初始化程序,我无法实例化模拟.
我甚至不确定我是否可以通过添加通知请求和获取当前通知来进行测试,因为测试需要在模拟器上请求权限以阻止测试.目前我已经将通知逻辑重构为包装器,所以我至少可以在整个应用程序中模拟它并手动测试.
我有比手动测试更好的选择吗?
如何构建一个NSPredicate,在Arrays对象中的任何位置查找搜索项?我不能很好地解释它,所以这是一个例子.
NSArray *array = @[@"Test String: Apple", @"Test String: Pineapple", @"Test String: Banana"];
NSString *searchText = @"Apple";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS[cd] %@", searchText];
NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];
NSLog(@"filteredArray: %@", filteredArray);
// filteredArray: (
// "Test String: Apple",
// "Test String: Pineapple"
// )
Run Code Online (Sandbox Code Playgroud)
但如果我使用NSString *searchText = @"Test Str Appl";我得到零结果.我希望它匹配此字符串的相同结果.
我正在寻找的是一个搜索功能,类似于在Xcode中,"快速打开"菜单,如果你的搜索字符串正确的措辞,只有字母是按照正确的顺序作为搭配也没关系.我真的希望这是有道理的.

我正在尝试使用networkx来读取gml文件(非常简单吧?),除非我尝试读取文件,我得到错误"networkx.exception.NetworkXError:not tokenize u'graph'at(3 ,1)"我不太熟悉gml或networkx,所以我自己无法诊断问题.
甚至更奇怪的是,我的同事将使用完全相同的文件运行完全相同的命令,并且它将执行而不会出错.此时我已经多次卸载并重新安装networkx,任何人都可以帮助确定错误可能来自何处?
import networkx as nx
g = nx.read_gml('disciplineNetwork.gml')
Run Code Online (Sandbox Code Playgroud)
Traceback(最近一次调用最后一次):
文件"",第1行,in
在read_gml中的文件"",第2行
文件"/usr/local/lib/python2.7/dist-packages/networkx/utils/decorators.py",第220行,在_open_file中= func(*new_args,**kwargs)
文件"/usr/local/lib/python2.7/dist-packages/networkx/readwrite/gml.py",第210行,在read_gml中G = parse_gml_lines(filter_lines(path),label,destringizer)
文件"/usr/local/lib/python2.7/dist-packages/networkx/readwrite/gml.py",第383行,在parse_gml_lines graph = parse_graph()中
文件"/usr/local/lib/python2.7/dist-packages/networkx/readwrite/gml.py",第372行,parse_graph curr_token,dct = parse_kv(next(tokens))
文件"/usr/local/lib/python2.7/dist-packages/networkx/readwrite/gml.py",第347行,在parse_kv中curr_token = next(令牌)
文件"/usr/local/lib/python2.7/dist-packages/networkx/readwrite/gml.py",第323行,在tokenize中(行[pos:],lineno + 1,pos + 1))
networkx.exception.NetworkXError:无法在(3,1)处对u'graph'进行标记化
我在使用更新服务的CBPeripheral时遇到了一些问题:我的物理设备有一个更新广告服务的按钮,但我的应用程序仍然在委托方法中读取旧服务didDiscoverServices.
虽然当我发现外设时didDiscoverPeripheral,我可以看到服务是最新的.
如果我再次运行应用程序,旧服务仍然存在!似乎让我的应用程序发现新服务的唯一方法是关闭蓝牙并重新打开.即使卸载/重新安装我的应用程序也是不够的.
iOS会永久缓存服务吗?有没有办法重置/擦除缓存?
我有一个UITableView略大于self.view.我UITextField在视图的底部有一个,– textFieldDidBeginEditing:当文本字段开始编辑时,我使用委托方法向上移动视图.
这样可以正常工作,但是如果我UITextField在编辑时尝试滚动视图(并且内容已经偏移),则内容会突然移动到视图的底部"适当"位置.换句话说,contentOffset.yI set被更改为等于内容视图的大小(正如您对正常行为所期望的那样).
任何想法如何在编辑时克服这种行为?
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
// Scroll to the currently editing text field
[self scrollViewToTextField:textField];
}
- (void)scrollViewToTextField:(id)textField
{
// Set the current _scrollOffset, so we can return the user after editing
_scrollOffsetY = self.tableView.contentOffset.y;
// Get a pointer to the text field's cell
UITableViewCell *theTextFieldCell = (UITableViewCell *)[textField superview];
// Get the text fields location
CGPoint point = [theTextFieldCell convertPoint:theTextFieldCell.frame.origin toView:self.tableView];
// Scroll …Run Code Online (Sandbox Code Playgroud) 假设我在Swift中有一个方便的初始化程序:
extension UIImage {
convenience init?(bundleNamed name: String) {
let bundle = NSBundle(forClass: Foo.self)
self.init(named: name, inBundle: bundle, compatibleWithTraitCollection: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能在Objective-C中调用它?以下不起作用:
[UIImage bundleNamed:@"Bar"];
[[UIImage alloc] initWithBundleNamed:@"Bar"];
Run Code Online (Sandbox Code Playgroud)
我是否只需要为Objective-C提供额外的类扩展?
解决方案:按照Lasse的回答,我必须做的步骤是:
在Objective-C类实现文件中,添加
#import <ModuleName-Swift.h>
Run Code Online (Sandbox Code Playgroud)
然后我不得不删除派生数据并重建.然后我能够使用便利初始化程序如下:
[[UIImage alloc] initWithBundleNamed: @"Bar"];
Run Code Online (Sandbox Code Playgroud)
我不需要声明初始化程序,public因为默认级别internal足以支持我的模块.
我有一个我正在处理的iOS应用程序,它连接到第三方Web服务.我有大约50个不同的调用,并希望使用Kiwi编写单元测试,但我不知道从哪里开始.
由于我不负责API,我需要使用正确的GET或POST方法检查我的调用是否指向正确的URL.
有没有办法正确测试?
下面是我的一个电话的例子:
+ (void)listsForUser:(NSString *)username
response:(void (^)(NSArray *lists))completion
{
NSString *path = [NSString stringWithFormat:@"user/list.json/%@/%@", TRAKT_API_KEY, username];
[TNTraktAPIManager requestWithMethod:GET
path:path
parameters:nil
callback:^(id response) {
completion(response);
}];
}
Run Code Online (Sandbox Code Playgroud)
其中调用以下辅助方法
+ (void)requestWithMethod:(HTTPMethod)method
path:(NSString *)path
parameters:(NSDictionary *)params
callback:(void (^)(id response))completion
{
NSString *methodString = @"POST";
if (method == GET) {
methodString = @"GET";
}
// Setup request
NSURLRequest *request = [[TraktAPIClient sharedClient] requestWithMethod:methodString
path:path
parameters:params];
// Setup operation
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request,
NSHTTPURLResponse *response,
id JSON) {
id jsonResults …Run Code Online (Sandbox Code Playgroud) 我有一个tableView在单元格中显示图像,我正在viewDidLoad函数中获取数据
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableview.dequeueReusableCellWithIdentifier("cardSelectionCell", forIndexPath: indexPath) as! MyCell
let card = fetchedResultsController.objectAtIndexPath(indexPath) as! Card
cell.Name?.text = card.name
var image: NSData = card.photo as NSData
cell.logo.image = UIImage(data: image)
let date = NSDate()
let formatter = NSDateFormatter()
formatter.timeStyle = .MediumStyle
cell.policyExpiryDate.text = formatter.stringFromDate(date)
return cell
}
Run Code Online (Sandbox Code Playgroud)
但问题是,当我开始滚动时,tableView非常滞后所以我试图创建一个字典来转换viewDidLoad()中的图像
var imageDictionary = [Card:UIImage]()
AllCards = context.executeFetchRequest(request, error: nil) as! [Card]
for card in AllCards { …Run Code Online (Sandbox Code Playgroud) ios ×5
iphone ×3
objective-c ×2
swift ×2
uitableview ×2
afnetworking ×1
bluetooth ×1
cbperipheral ×1
core-data ×1
git ×1
graph ×1
image ×1
ios10 ×1
json ×1
kiwi ×1
networkx ×1
nsdata ×1
nspredicate ×1
python ×1
uiscrollview ×1
unit-testing ×1
xcode ×1