nsobject

How is comparing operator '==' for NSObject [duplicate]

自作多情 提交于 2019-12-13 09:12:04
问题 This question already has answers here : Should you use 'isEqual' or '=='? (2 answers) Closed 5 years ago . How is comparing operator ' == ' for NSObject ? Method -isEqual: works fine for me, but when I'm using -isEqual I need to check if objects exists. With ' == ' I don't need to check this but where I can find documentation for it? 回答1: From Apple documentation: Returns a Boolean value that indicates whether the receiver and a given object are equal. (required) This method defines what it

How to make performSelector:withObject:afterDelay work?

人盡茶涼 提交于 2019-12-13 08:29:09
问题 Here's the code: -(void)setProjectID:(NSString *)newProject { [self willChangeValueForKey:@"projectID"]; [projectID release]; projectID = [newProject copy]; [self didChangeValueForKey:@"projectID"]; // Since we have an ID, now we need to load it NSInvocation *returnInvocation = [NSInvocation invocationWithMethodSignature: [Detail instanceMethodSignatureForSelector:@selector(configureView:)]]; [returnInvocation setTarget:self]; [returnInvocation performSelector:@selector(displayAlert)

Convert NSObject to JSON string

Deadly 提交于 2019-12-13 02:45:32
问题 I have a class that conforms to NSObject and has fields like NSNumber and NSMutableArray, so cannot really use Codable here. So the class is like this: class Custom: NSObject { var users: NSMutableArray? var type: NSNumber? .. and many more fields } Now i have an object of this class and want to get JSON string from that object : I have tried following : let json = try? JSONSerialization.data(withJSONObject: customObject, options: JSONSerialization.WritingOptions.prettyPrinted) as? [String:

iOS - Locally saving an array of key value pairs

杀马特。学长 韩版系。学妹 提交于 2019-12-13 02:38:34
问题 In an app I'm developing the user needs to add an "enterprise" to use the app. However, they can add more than one "enterprise" to the app. Every enterprise added needs two things: a name, and an enterprise API key. I have created an "Enterprise" class: class Enterprise : NSObject { var name:String! var apiKey:String! init (name:String, apiKey:String) { self.name = name self.apiKey = apiKey } required init(coder decoder: NSCoder) { self.name = decoder.decodeObjectForKey("name") as String self

KVO listener issues in Swift 4

回眸只為那壹抹淺笑 提交于 2019-12-12 16:28:56
问题 I am using ViewModel class and want to setup observer if any changes into loginResponse variable. @objcMembers class ViewModel: NSObject { var count = 300 @objc dynamic var loginResponse :String override init() { loginResponse = "1" super.init() setupTimer() } func setupTimer(){ _ = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector:#selector(callTimer), userInfo: nil, repeats: true) } func callTimer(){ let minutes = String(count / 60) let seconds = String(count % 60)

Play audio with AVAudioPlayer inside NSObject class

青春壹個敷衍的年華 提交于 2019-12-12 16:28:25
问题 To organize things , I decided to create a class called SoundPlayer where will run all audio files from my app. (This would avoid having many duplicate codes) SoundPlayer.h #import <Foundation/Foundation.h> #import <AVFoundation/AVFoundation.h> #include <AudioToolbox/AudioToolbox.h> @interface SoundPlayer : NSObject <AVAudioPlayerDelegate> @property (strong,nonatomic) AVAudioPlayer *backgroundMusicPlayer; -(void)PlaySound:(NSString*)name extension:(NSString*)ext loops:(int)val; @end

How to remove all objects with the same property value but one in NSMutableArray

有些话、适合烂在心里 提交于 2019-12-12 13:15:58
问题 I have a history object with a url string property and title. I want to search all the history for objects with the url containing a search string, then remove all duplicates. Example: I have an array of history objects and 20 of them are all "https://www.google.com" and 4 are "https://www.google.com/#q=search", I want to get an array back with only one object with the url value of "https://www.google.com" and one url value of "https://www.google.com/#q=search" Here is my current code that

How to save to and read from a NSObject

佐手、 提交于 2019-12-12 10:23:05
问题 I have two NSObject's. @interface Car : NSObject{ @property (strong) NSSet *cars; } and @interface Model : NSObject{ @property (strong) UIImage *picture; @property (strong) NSString *name; } Basically the object Car has a NSSet cars and each object of the NSSet cars has the properties picture and name. How can I relate this two NSObject's and how can I save a string or image to the Car NSSet using the properties of the Model NSObject. Thanks. 回答1: For easy adding or removing, your " cars "

Custom class to create an Alert with Buttons. How to add a completition handler?

好久不见. 提交于 2019-12-12 03:38:16
问题 I was trying to create a custom alert and I am getting mad trying to implement a completition handler on the buttons. I have tried a few things, the last, create func array to pass in the selector addTarget function of the UIButton, but not working. (where the ****** are) The issue: "Argument of #selector does no refer to @obc method, property or initializer" The difficult coding part I can't do is to configure the selector with some code I receive from my view controller where I create an

How to copy custom NSObject into NSMutableArray

左心房为你撑大大i 提交于 2019-12-12 00:29:15
问题 NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error]; NSArray* users = [json objectForKey:@"Users"]; NSEnumerator* enumerator = [users objectEnumerator]; id element; NSMutableArray *results; Result *fetchedResults; while(element = [enumerator nextObject]) { // fetchedResults = [[Result alloc] init]; // i have tried commenting/uncommenting fetchedResults.name = (NSString *)[[element objectForKey:@"User"] objectForKey:@"name"];