NSMutableArray *sectionTitles;
[sectionTitles addObject:due];
Run Code Online (Sandbox Code Playgroud)
如何只为数组添加唯一值?
我有以下情况:
NSDictionary *params = @{
@"Checkout" : @{
@"conditions" : @{@"Checkout.user_id" : @1},
@"order" : @{@"Checkout.id" : @"DESC"}
},
@"PaymentState" : @[],
@"Offer" : @[]
};
Run Code Online (Sandbox Code Playgroud)
此字典包含传递带有Web服务URL的JSON字符串的Web服务请求的参数.我使用NSJSONSerialization类获取JSON字符串,如下所示:
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
Run Code Online (Sandbox Code Playgroud)
问题是:jsonString"keys"的顺序与原来的params字典键顺序不同,如下所示:
{
"Offer":[],
"PaymentState":[],
"Checkout":{
"conditions":{"Checkout.user_id":6},
"order":{"Checkout.id":"DESC"}
}
Run Code Online (Sandbox Code Playgroud)
}
也就是说,"PaymentState"和"Offer"键首先出现在jsonString中,我需要保持原始顺序.这非常重要,如下:
{
"Checkout":{
"conditions":{"Checkout.user_id":6},
"order":{"Checkout.id":"DESC"}
},
"Offer":[],
"PaymentState":[]
Run Code Online (Sandbox Code Playgroud)
}
那么伙计们,我怎么能这样做?
我试图在Swift中的视图之间传递变量,并遇到了相当抽象的协议和委托概念.
然后我尝试在第二个视图中存储对第一个视图的引用,并直接调用函数.这似乎有效:
屏幕1
class Screen1: UIViewController {
var myName = "Screen1"
override func viewDidLoad() {
super.viewDidLoad()
}
//
// checking if the segue to screen 2 is called and then passing a reference
//
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if segue.identifier == "screen2Segue"{
let vc = segue.destinationViewController as Screen2
vc.storedReference = self
}
}
func getName() -> String {
return myName
}
}
Run Code Online (Sandbox Code Playgroud)
屏幕2
class Screen2: UIViewController {
var storedReference:Screen1!
override func viewDidLoad() {
super.viewDidLoad()
}
func testReference() …Run Code Online (Sandbox Code Playgroud) 好的,所以我有这个,但它不会工作:
@interface UILabel (touches)
@property (nonatomic) BOOL isMethodStep;
@end
@implementation UILabel (touches)
-(BOOL)isMethodStep {
return self.isMethodStep;
}
-(void)setIsMethodStep:(BOOL)boolean {
self.isMethodStep = boolean;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if(self.isMethodStep){
// set all labels to normal font:
UIFont *toSet = (self.font == [UIFont fontWithName:@"Helvetica" size:16]) ? [UIFont fontWithName:@"Helvetica-Bold" size:16] : [UIFont fontWithName:@"Helvetica" size:16];
id superView = self.superview;
for(id theView in [(UIView *)superView subviews])
if([theView isKindOfClass:[UILabel class]])
[(UILabel *)theView setFont:[UIFont fontWithName:@"Helvetica" size:16]];
self.font = toSet;
}
}
@end
Run Code Online (Sandbox Code Playgroud)
如果我取出getter和setter方法然后它不起作用它告诉我我需要创建一些getter和setter方法(或者使用@synthesize - 但是在@implementation中放入@synthesize也会引发错误).但是使用getter和setter方法,我得到一个EXC_BAD_ACCESS和崩溃.有任何想法吗?谢谢
汤姆
我有一个NSObject,它是一个单身人士.有没有为这个单身人士课程设立代表的问题?我担心单身人士会失败.
这是我的情景.我有一个函数(在这个单例类中),它执行异步请求以从API中提取NSDictionary.基本上,当这个请求完成时,我想通知一个类请求已经完成.
我正在尝试创建一个原型来将文本文件的位图数据打印到支持LAN的epson pos打印机TM-T88V.
虽然我没有问题发送文本和文本格式说明,我不明白,我必须做什么,让我的打印机打印Arecibo消息的数据.
前几行:
00000010101010000000000
00101000001010000000100
10001000100010010110010
10101010101010100100100
00000000000000000000000
00000000000011000000000
00000000001101000000000
00000000001101000000000
00000000010101000000000
00000000011111000000000
00000000000000000000000
11000011100011000011000
10000000000000110010000
11010001100011000011010
11111011111011111011111
00000000000000000000000
00010000000000000000010
00000000000000000000000
00001000000000000000001
Run Code Online (Sandbox Code Playgroud)
该消息有73行和23列,产生1679个图像元素.每个元素由1表示黑色或0表示为白色,应打印为8x8(或16x16)点的正方形.结果会导致
Arecibo消息http://www.satsig.net/seti/message-to-gliese-581.gif
从打印机的规格:
虽然 - 正如我所说 - 连接和发送到打印机是没有问题的,我只是不明白,这个指令想告诉我什么.在Arecibo消息的情况下会是什么
我必须向打印机发送什么号码?我需要发送每个点吗?什么nL, nH specify the number of dots of the image data in the horizontal direction as (nL + nH × 256).意思?
这是我用于原型设计的简单Python程序:
# -*- coding: utf-8 -*-
import struct
import socket
def sendInstructions(mySocket,l):
for x in l:
mySocket.send(struct.pack('h', *[x]),1)
def emphasizeOn(mySocket):
sendInstructions(mySocket,[27,33,48])
def emphasizeOff(mySocket):
sendInstructions(mySocket,[27,33,0]) …Run Code Online (Sandbox Code Playgroud) 我试图获取匹配用户selectedDate的实体中的所有对象(它是一个NSDate).核心数据代码很好,但我的谓词不断返回0结果,数据库中的日期与用户选择的相同.
应该如何将selectedDate与使用谓词的实体的日期进行比较?
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(eDate = %@)", selectedDate];
Run Code Online (Sandbox Code Playgroud) 我是iOS开发新手,我正在尝试解析一个本地Json文件,如
{"quizz":[{"id":"1","Q1":"When Mickey was born","R1":"1920","R2":"1965","R3":"1923","R4","1234","response","1920"},{"id":"1","Q1":"When start the cold war","R1":"1920","R2":"1965","R3":"1923","rep4","1234","reponse","1920"}]}
这是我的代码:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"];
NSString *myJSON = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
// Parse the string into JSON
NSDictionary *json = [myJSON JSONValue];
// Get all object
NSArray *items = [json valueForKeyPath:@"quizz"];
NSEnumerator *enumerator = [items objectEnumerator];
NSDictionary* item;
while (item = (NSDictionary*)[enumerator nextObject]) {
NSLog(@"clientId = %@", [item objectForKey:@"id"]);
NSLog(@"clientName = %@",[item objectForKey:@"Q1"]);
NSLog(@"job = %@", [item objectForKey:@"Q2"]);
}
Run Code Online (Sandbox Code Playgroud)
我在这个网站上找到了一个样本,但是我收到了以下错误
-JSONValue失败.错误是:在对象键之后不期望令牌'值分隔符'.
我正在使用新版本的AFNetworking,我无法弄清楚如何阅读响应的标题.我正在使用AFHTTPSessionManager来执行我的查询,一切正常但我无法找到标题响应字段.
这是我如何进行
self.sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:BASE_URL]];
[self.sessionManager GET:urlId parameters:nil
success:^(NSURLSessionDataTask *task, id responseObject) {
if ([self.delegate respondsToSelector:@selector(userIsLoadedWithInfos:)]) {
[self.delegate userIsLoadedWithInfos: responseObject];
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if ([self.delegate respondsToSelector:@selector(userLoadingFailed)]) {
[self.delegate userLoadingFailed];
}
}
];
Run Code Online (Sandbox Code Playgroud)
我尝试读取任务的响应属性,但它返回一个不包含标题的NSURLResponse.现在有人如何阅读2.0版本的响应标头?谢谢
我使用以下代码来查看文本
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:(text ? text : @"")];
[attributeString addAttribute:NSStrikethroughStyleAttributeName
value:@2
range:NSMakeRange(0, [attributeString length])];
label.attributedText = attributeString;
Run Code Online (Sandbox Code Playgroud)
文字为白色,因此删除线也是白色.我想把它改成红色.我怎么能这样做?
objective-c ×8
ios ×6
cocoa-touch ×4
categories ×1
cocoa ×1
delegates ×1
epson ×1
ios7 ×1
json ×1
nsdate ×1
predicate ×1
protocols ×1
python ×1
swift ×1
uilabel ×1