[Solved] Determining the type of an iOS device in Xcode [duplicate]

– (NSString *) IphoneModel { size_t size; sysctlbyname(“hw.machine”, NULL, &size, NULL, 0); char *machine = (char*)malloc(size); sysctlbyname(“hw.machine”, machine, &size, NULL, 0); NSString *platform = [NSString stringWithCString:machine encoding: NSUTF8StringEncoding]; free(machine); if ([platform isEqualToString:@”iPhone1,1″]) return @”iPhone 1G”; if ([platform isEqualToString:@”iPhone1,2″]) return @”iPhone 3G”; if ([platform isEqualToString:@”iPhone2,1″]) return @”iPhone 3GS”; if ([platform isEqualToString:@”iPhone3,1″]) return @”iPhone 4″; if ([platform … Read more

[Solved] Multiple Arrays in Multiple UITableViewCell [closed]

you can Add value from different array in different cell like bellow.. Also i add controls in UITableCell for just an example which through you can add multiple controls in the cell with frame.. – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* cellIdentifier = @”gridCell”; UITableViewCell *yourCell = [tableView dequeueReusableCellWithIdentifier:nil]; if(yourCell == nil) { … Read more

[Solved] How to read formatted string from a text file?

ok so this is how I did it … I just used the fact that ObjC is a superset of C char personName[256]; char imgFilename[512]; int personNumber; NSArray *array = [outputString componentsSeparatedByString:@”\n”]; int lines = [array count]; FILE *file = fopen([filePath UTF8String],”r”); for (int i = 0; i<lines; i++) { fscanf(file,”%d %s %s”,&personNumber, personName, imgFilename); … Read more

[Solved] SwiftUI – how to observe(.sink/ .onReceive) PassthroughSubject inside a View [closed]

If you have a Struct as Model or ViewModel and you need to update your SwiftUI View here it is how to do just that with SwiftUI + Combine. import Combine struct ViewModel { var textChangedPublisher: AnyPublisher<String, Never> { textChangedSubject.eraseToAnyPublisher() } private let textChangedSubject = PassthroughSubject<String, Never>() func triggerUpdate() { let newStr = DateFormatter().string(from: Date()) … Read more

[Solved] How to pass NSUInteger into NSDictionary

You can use NSNumber class for doing the same: NSDictionary *parameters = @{@”index”:[NSNumber numberWithUnsignedInteger:indexPath.row]}; Or in Modern Objective C: NSDictionary *parameters = @{@”index”:@(indexPath.row)}; 0 solved How to pass NSUInteger into NSDictionary

[Solved] How to send data to the server(api) using swift

you can send data to server by using Alamofire API. It’s documention and implemention all the stuff are mentioned in the following link. https://github.com/Alamofire/Alamofire Just install it using Pods and it’s very easy to implement. create Network Class and create following function inside it. func get_Request(currentView : UIViewController,action : NSString,completionHandler: (NSDictionary -> Void)) { print(“Url==>>>”,mainURl … Read more

[Solved] Why is this out of index?

Not sure what this is: var mainController = ViewController() var movie = ViewController().self.movieArray[0] Regardless, ViewController() instantiates a new object of that class. At that point, it’s very likely movieArray has never been initialized and has no objects in it. 5 solved Why is this out of index?

[Solved] How to change text color in tableView section in swift

override func tableView(tableView: UITableView!, viewForHeaderInSection section: Int) -> UIView! { var customView:UIView? customView.frame = // set frame according to tableview width and header height customView.backgroundColor = UIColor.greenColor() return customView } Hope this will help you. solved How to change text color in tableView section in swift

[Solved] Add 1 Day to a Date [closed]

The most reliable way to get the next occurrence of a time is nextDate(after:matching:matchingPolicy: of Calendar because it considers also daylight saving changes. assuming datePicker is the NSDatePicker instance: let date = datePicker.date let calendar = Calendar.current // get hour and minute components of the given date let components = calendar.dateComponents([.hour, .minute], from: date) // … Read more

[Solved] While decoding json from webservice, it shows an error: Could not cast value of type ‘__NSArrayM’ (0x10b84bdb0) to ‘NSDictionary’ (0x10b84c288)

Try this var desriptionArray = [String]() for dataValues in responseObject[“result”] as! [[String: AnyObject]] { let name = dataValues [“description”] as! String desriptionArray .append(name) } OR for (index , element) in (responseObject[“result”] as! [Any]).enumerated() { let nameDict = element as! [String : AnyObject] let strDecription = nameDict[“description”] as! String desriptionArray .insert(strDecription, at: index) } solved While … Read more

[Solved] Scrollview content center alignment in iOS app [closed]

I will give u a HINT: Take the scrollView’s bounds, get midX, say X1. Take all the visible button’s frames, and then their frame’s midX, say X2’s. Calculate absolute differences, between X1 and X2’s, whichever button has the smallest one, scroll the scrollview to that button’s frame. Have Fun. Cheers 1 solved Scrollview content center … Read more

[Solved] Textfield values set to empty when coming back from previous view controller [closed]

When you push back to the origin viewController, It’s better to replace using “push” Segue by “popViewController” method . It’s also good using data consistent strategy. And the reason: You should consider the viewController’s lifecycle. When you push back to the origin viewController, using “push” Segue makes the origin viewController’s “viewDidLoad” method is called again. … Read more