在PHP中生成用户唯一性的"指纹"的最佳方法是什么?
例如:
理想情况下,指纹标记"机器"而不是浏览器或"ip",但我想不出这是如何实现的.
随时了解您如何唯一识别用户的想法/建议,以及您的方法有哪些优点/缺点.
我有一个类从URL检索JSON并通过协议/委托模式返回数据.
MRDelegateClass.h
#import <Foundation/Foundation.h>
@protocol MRDelegateClassProtocol
@optional
- (void)dataRetrieved:(NSDictionary *)json;
- (void)dataFailed:(NSError *)error;
@end
@interface MRDelegateClass : NSObject
@property (strong) id <MRDelegateClassProtocol> delegate;
- (void)getJSONData;
@end
Run Code Online (Sandbox Code Playgroud)
请注意,我正在使用strong
我的委托属性.以后更多关于......
我正在尝试编写一个"包装"类,它以基于块的格式实现getJSONData.
MRBlockWrapperClassForDelegate.h
#import <Foundation/Foundation.h>
typedef void(^SuccessBlock)(NSDictionary *json);
typedef void(^ErrorBlock)(NSError *error);
@interface MRBlockWrapperClassForDelegate : NSObject
+ (void)getJSONWithSuccess:(SuccessBlock)success orError:(ErrorBlock)error;
@end
Run Code Online (Sandbox Code Playgroud)
MRBlockWrapperClassForDelegate.m
#import "MRBlockWrapperClassForDelegate.h"
#import "MRDelegateClass.h"
@interface DelegateBlock:NSObject <MRDelegateClassProtocol>
@property (nonatomic, copy) SuccessBlock successBlock;
@property (nonatomic, copy) ErrorBlock errorBlock;
@end
@implementation DelegateBlock
- (id)initWithSuccessBlock:(SuccessBlock)aSuccessBlock andErrorBlock:(ErrorBlock)aErrorBlock {
self = [super init];
if (self) {
_successBlock …
Run Code Online (Sandbox Code Playgroud) delegates memory-management objective-c objective-c-blocks automatic-ref-counting
我有一个自定义的UIView子类,它在初始化过程中以编程方式添加子视图.我希望这个子视图与自定义UIView的宽度相同.
如果我以编程方式添加自定义UIView,我的代码工作正常.但是,当通过StoryBoard初始化UIView时,我无法获得自定义UIView的宽度.
// Init programatically
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog (@"view: %f", self.frame.size.width); //WILL return width
NSLog (@"view: %f", self.bounds.size.width); //WILL return width
}
return self;
}
// Init from storyboard
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
NSLog (@"view: %f", self.frame.size.width); //Returns 0
NSLog (@"view: %f", self.bounds.size.width); //Returns 0
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
当initWithCoder:由StoryBoard运行时,UIView的框架和边界都返回为0.有没有办法在 initWithCoder 中访问UIView的尺寸?或者,至少在调用drawRect:之前访问维度?
谢谢.
我有以下包含NSDictionary的NSArray:
NSArray *data = [[NSArray alloc] initWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1], @"bill", [NSNumber numberWithInt:2], @"joe", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:3], @"bill", [NSNumber numberWithInt:4], @"joe", [NSNumber numberWithInt:5], @"jenny", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:6], @"joe", [NSNumber numberWithInt:1], @"jenny", nil],
nil];
Run Code Online (Sandbox Code Playgroud)
我想创建一个过滤的NSArray,它只包含NSDictionary使用NSPredicate匹配多个"键"的对象.
例如:
任何人都可以解释NSPredicate的格式来实现这一目标吗?
编辑:我可以使用以下方法获得与所需NSPredicate类似的结果:
NSMutableArray *filteredSet = [[NSMutableArray alloc] initWithCapacity:[data count]];
NSString *keySearch1 = [NSString stringWithString:@"bill"];
NSString *keySearch2 = [NSString stringWithString:@"joe"];
for (NSDictionary *currentDict in data){
// objectForKey will return nil if a key doesn't exists.
if ([currentDict objectForKey:keySearch1] …
Run Code Online (Sandbox Code Playgroud) 只是玩SpriteKit,我试图弄清楚如何捕获SKNode的'抓取'到UIImage.
使用UIView(或UIView子类),我使用layer
视图的属性渲染到图形上下文中.
例如.
#import <QuartzCore/QuartzCore.h>
+ (UIImage *)imageOfView:(UIView *)view {
UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *viewShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewShot;
}
Run Code Online (Sandbox Code Playgroud)
SKNode不是UIView的子类,因此似乎没有图层支持.
关于如何将给定的SKNode呈现给UIImage的任何想法?
考虑以下NSArray:
NSArray *dataSet = [[NSArray alloc] initWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"abc", @"key1", @"def", @"key2", @"hij", @"key3", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"klm", @"key1", @"nop", @"key2", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"qrs", @"key2", @"tuv", @"key4", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"wxy", @"key3", nil],
nil];
Run Code Online (Sandbox Code Playgroud)
我能够过滤此数组以查找包含密钥的字典对象 key1
// Filter our dataSet to only contain dictionary objects with a key of 'key1'
NSString *key = @"key1";
NSPredicate *key1Predicate = [NSPredicate predicateWithFormat:@"%@ IN self.@allKeys", key];
NSArray *filteretSet1 = [dataSet filteredArrayUsingPredicate:key1Predicate];
NSLog(@"filteretSet1: %@",filteretSet1);
Run Code Online (Sandbox Code Playgroud)
适当回报:
filteretSet1: (
{
key1 = abc;
key2 = def;
key3 …
Run Code Online (Sandbox Code Playgroud) 我在找出确定UICollectionView何时完成动画的方法时遇到了问题.
我目前有一个UICollectionView,它使用两个子类流程布局之间的动画 setCollectionViewLayout:animated:
动画看起来很棒,但是,如果用户在动画期间选择了一个单元格,我会遇到一些不良行为.
我期待在忽略细胞"选择"通过返回NO
通过UICollectionViewDelegate
方法collectionView:shouldSelectItemAtIndexPath:
-然而-我想不出一个可靠的测试,以查看是否集合视图当前动画.
有任何想法吗?
在听取了关于实现以下结果的最佳方法的一些意见之后:
我想在我的MySQL数据库中存储可以由用户投票的产品(每个投票值+1).我还希望能够看到用户投票的总次数.
简单来说,下表结构是理想的:
table: product table: user table: user_product_vote
+----+-------------+ +----+-------------+ +----+------------+---------+
| id | product | | id | username | | id | product_id | user_id |
+----+-------------+ +----+-------------+ +----+------------+---------+
| 1 | bananas | | 1 | matthew | | 1 | 1 | 2 |
| 2 | apples | | 2 | mark | | 2 | 2 | 2 |
| .. | .. | | .. | .. | | .. | .. …
Run Code Online (Sandbox Code Playgroud) 我很感激任何帮助解决我的问题让我在最后一天拔头发!
免责声明1 我是一个Objective-C菜鸟 - 所以答案可能非常简单(我来自多年的PHP).请友好一点.
免责声明2 是的,我已经广泛"谷歌搜索"并查看了Apple文档 - 但未能理解我的问题.
摘要
我试图将表视图中选择的值从单例传递给另一个控制器.我发现第二个视图控制器中的viewDidLoad方法在tableView:didSelectRowAtIndexPath:方法之前完成,该方法触发了segue.这导致第二个视图控制器访问"陈旧"数据.
详情
我使用针对iOS5的ARC设置了一个非常简单的StoryBoard项目.
我创建了一个单例来在视图控制器之间存储NSString.
Singleton.h
#import <Foundation/Foundation.h>
@interface Singleton : NSObject
@property (strong, nonatomic) NSString *sharedString;
+ (id)singletonManager;
@end
Run Code Online (Sandbox Code Playgroud)
Singleton.m
#import "Singleton.h"
static Singleton *sharedInstance = nil;
@implementation Singleton
@synthesize sharedString = _sharedString;
+(id)singletonManager
{
@synchronized(self){
if (sharedInstance == nil)
sharedInstance = [[self alloc] init];
}
return sharedInstance;
}
-(id) init {
if (self = [super init]) {
_sharedString = [[NSString alloc] initWithString:@"Initialization String"];
}
return …
Run Code Online (Sandbox Code Playgroud) 我只是围绕Swift - 然后来了Swift 1.2(打破我的工作代码)!
我有一个基于NSHipster的代码示例的函数 - CGImageSourceCreateThumbnailAtIndex.
我以前工作的代码是:
import ImageIO
func processImage(jpgImagePath: String, thumbSize: CGSize) {
if let path = NSBundle.mainBundle().pathForResource(jpgImagePath, ofType: "") {
if let imageURL = NSURL(fileURLWithPath: path) {
if let imageSource = CGImageSourceCreateWithURL(imageURL, nil) {
let maxSize = max(thumbSize.width, thumbSize.height) / 2.0
let options = [
kCGImageSourceThumbnailMaxPixelSize: maxSize,
kCGImageSourceCreateThumbnailFromImageIfAbsent: true
]
let scaledImage = UIImage(CGImage: CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options))
// do other stuff
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
从Swift 1.2开始,编译器提供了两个与options
字典相关的错误:
JavaScript新手.
寻求关于如何使用ES6类从超类中定义的静态方法访问调用类名的一些指导.我花了一个小时搜索,但一直没能找到解决方案.
代码片段可能有助于澄清我在寻找什么
class SuperClass {
get callingInstanceType() { return this.constructor.name }
static get callingClassType() { return '....help here ...' }
}
class SubClass extends SuperClass { }
let sc = new SubClass()
console.log(sc.callingInstanceType) // correctly prints 'SubClass'
console.log(SubClass.callingClassType) // hoping to print 'SubClass'
Run Code Online (Sandbox Code Playgroud)
如上所示,我可以轻松地从实例中获取子类名称.不太确定如何从静态方法访问.
static get callingClassType()
欢迎实施的想法.
目标:使用优雅代码获取包含给定NSDictionary的唯一键的NSArray
带当前工作解决方案的示例代码
NSArray *data = [[NSArray alloc] initWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1], @"a", [NSNumber numberWithInt:2], @"b", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:3], @"b", [NSNumber numberWithInt:4], @"c", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:5], @"a", [NSNumber numberWithInt:6], @"c", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:7], @"b", [NSNumber numberWithInt:8], @"a", nil],
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:8], @"c", [NSNumber numberWithInt:9], @"b", nil],
nil];
// create an NSArray of all the dictionary keys within the NSArray *data
NSMutableSet *setKeys = [[NSMutableSet alloc] init];
for (int i=0; i<[data count]; i++) {
[setKeys addObjectsFromArray:[[data objectAtIndex:i] allKeys]]; …
Run Code Online (Sandbox Code Playgroud) objective-c ×8
nsarray ×3
ios ×2
nspredicate ×2
cgimage ×1
cocoa ×1
delegates ×1
dictionary ×1
es6-class ×1
fingerprint ×1
foundation ×1
identifier ×1
javascript ×1
kvc ×1
mysql ×1
nsdictionary ×1
php ×1
segue ×1
singleton ×1
sknode ×1
sprite-kit ×1
statistics ×1
swift ×1
uiimage ×1
uistoryboard ×1
uitableview ×1
uiview ×1
user-agent ×1