In my OS X app I'm trying to fetch application's support directory. But I'm getting wrong results.
using:
FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)
returns
///Users/chandresh/Library/Application%20Support/
instead
/Users/chandresh/Library/Containers/com.thinkbizz.ThinkBizz-Business-Dynamics/Data/Library/Application%20Support/
Although, it returns correct result while using SandBox.
It doesn't give me correct path without SandBox
Post not yet marked as solved
I'm facing issue from few days with CloudKit. When I try to fetch any record from Cloudkit it gives me following error:
<CKError 0x6000006ec420: "Service Unavailable" (6/2022); "Request failed with http status code 503"; Retry after 30.0 seconds>
Also, when I try to query records from Cloudkit dashboard I receive "Internal error".
I have not done any write operations.
Please help if anyone has solved this type of error.
Post not yet marked as solved
Hello,
I was running macOS app on old iMac. But when I tried to run the same code on MacBook Air M1 on Monterey I receive following error.
I tried searching solution everywhere, but no solution has been found.
Please help if anyone able to resolve this issue.
Translated Report (Full Report Below)
Incident Identifier: 656E6540-596D-4ACC-98E1-3B3339992FF0
CrashReporter Key: 8EC66A36-1996-E656-76D7-FE1144ACDA5D
Hardware Model: MacBookAir10,1
Process: ThinkBizz Business Dynamics [16320]
Path: /Users/USER/Library/Developer/Xcode/DerivedData/ThinkBizz_Business_Dynamics-byvoiahkkwoisueapzfaqupjnobh/Build/Products/Debug/ThinkBizz Business Dynamics.app/Contents/MacOS/ThinkBizz Business Dynamics
Identifier: com.ThinkBizz.TBD
Version: 1.0 (1)
Code Type: X86-64 (Native)
Role: Background
Parent Process: launchd [1]
Coalition: com.ThinkBizz.TBD [2258]
Date/Time: 2022-01-14 15:28:28.9350 +0530
Launch Time: 2022-01-14 15:28:28.8352 +0530
OS Version: macOS 12.1 (21C52)
Release Type: User
Report Version: 104
Exception Type: EXC_CRASH (SIGKILL (Code Signature Invalid))
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: CODESIGNING 1
Triggered by Thread: 0
Thread 0 Crashed:
0 0x7ff7ffd5ba2c 0x7ff7ffd58000 + 14892
Binary Images:
0x7ff7ffd58000 - 0x7ff7ffd87fff (*) <21c1e0c9-a36e-3e4b-a12b-1bf54ce4403e> ???
Error Formulating Crash Report:
dyld_process_snapshot_get_shared_cache failed
EOF
Post not yet marked as solved
I'm using MBProgressHUD in my cocoa app(https://github.com/Foxnolds/MBProgressHUD-OSX).
It's working fine when I show on app's main window.
I'm showing new modal window using
		 NSApplication.shared.runModal(for: wc.window!)
Now, when I try to ProgressHUD above this window. It doesn't show on this modal window, instead it shows on mainWindow only and progressHUD doesn't hide also.
Post not yet marked as solved
In my project, I've used NSCollectionView with a custom cell item. I want only a single selection on collectionView.In the collectionViewItem I've many textFields & buttons. I'm able to select a specific cell on click. But I'm not able to deselect again clicking on same cell.Though I have used following code to deselect cell:var clickGesture: NSClickGestureRecognizer!
override var isSelected: Bool {
didSet {
if isSelected {
mainBox.borderType = .lineBorder
//shortContentBox.fillColor = NSColor(red: 72/255, green: 112/255, blue: 255/255, alpha: 0.05)
mainBox.addSelectionShadow()
addGestureRecognizer()
} else {
mainBox.borderType = .noBorder
//shortContentBox.fillColor = .controlColor
mainBox.removeShadow()
removeGestureRecognizer()
}
}
}
func addGestureRecognizer() {
clickGesture = NSClickGestureRecognizer(target: self, action: #selector(onItemClick(_:)))
clickGesture.buttonMask = 0x1
clickGesture.numberOfClicksRequired = 2
view.addGestureRecognizer(clickGesture)
}
func removeGestureRecognizer() {
view.removeGestureRecognizer(clickGesture)
clickGesture = nil
}
@objc func onItemClick(_ sender: NSGestureRecognizer?) {
collectionView?.deselectAll(nil)
}My problem is, now I'm not able to click on textField or button, after selecting the cell. While I'm able to click on textField when the cell is not selected.Any suggestions? How do I achieve selection & deselection on click?
Post not yet marked as solved
Hi, I wanted to show open file app like Xcode, before opening application's main window.Tried many ways, but didn't find any luck.
Hi, I'm trying use Formatter for NSTextField to set maximum string length.I found this https://stackoverflow.com/questions/827014/how-to-limit-nstextfield-text-length-and-keep-it-always-upper-caseBut it's for objective-c. I tried this for swift, but it's not workingfunc controlTextDidChange(_ obj: Notification) {
if let info = obj.userInfo, let text = info["NSFieldEditor"] as? NSText {
let formatter = TextFieldFormatter()
formatter.maxLength = 10
let string = text.string
text.string = formatter.string(for: string.capitalized)!
}
}Custom formatter class:class TextFieldFormatter: Formatter {
var maxLength = 0
func setMaximumLength(_ len: Int) {
maxLength = len
}
func maximumLength() -> Int {
return maxLength
}
override init() {
super.init()
maxLength = Int(Int32.max)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func string(for obj: Any?) -> String? {
return obj as? String
}
override func getObjectValue(_ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?, for string: String, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool {
obj?.pointee = string as AnyObject
return true
}
override func isPartialStringValid(_ partialStringPtr: AutoreleasingUnsafeMutablePointer<NSString>, proposedSelectedRange proposedSelRangePtr: NSRangePointer?, originalString origString: String, originalSelectedRange origSelRange: NSRange, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool {
let size = partialStringPtr.pointee.length
if size > maxLength {
return false
} else {
return true
}
}
}
Post not yet marked as solved
I have a MacOS ERP project, and I'm using Core Data to store my data.I want to create multiple core data store & configuration for each store at runtime.Is there any way achieve this?
I have an collectionView. I'm increasing it's height on selction. But, I want add animation on increasing height.How do I achieve in sizeForItemAt method.func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
if let selectedRow = selectedRow {
if selectedRow == indexPath.item {
return NSSize(width: collectionView.bounds.width, height: 572)
}
}
return NSSize(width: collectionView.bounds.width, height: 71)
}
Hello, I'm building chat app, and also using CoreData to store messages.I have rotated my collectionView, so that it looks like it's going bottom to up.I have rotated my collectionView in viewDidLoad()override func viewDidLoad() {
super.viewDidLoad()
msgsCollectionView.delegate = self
msgsCollectionView.dataSource = self
//observeUserMessages()
//rotate collectionView 180º
msgsCollectionView.transform = CGAffineTransform.init(rotationAngle: (-(CGFloat)(Double.pi)))
//move scroll indicator from right to left
msgsCollectionView.scrollIndicatorInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: msgsCollectionView.bounds.size.width - 7)
attemptFetch()
}Then, I have rotated each cell in cellForRowAtfunc collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let message = controller.object(at: indexPath)
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MessageCell", for: indexPath) as? MessageCell {
cell.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
if let messageText = message.text {
let size = CGSize(width: 250, height: 1000)
let options = NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin)
let estimatedFrame = NSString(string: messageText).boundingRect(with: size, options: options, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14), NSAttributedString.Key.foregroundColor: UIColor.darkGray], context: nil)
if !message.isSender {
cell.msgTextView.frame = CGRect(x: 8, y: 0, width: estimatedFrame.width + 16, height: estimatedFrame.height + 18)
cell.textBubbleView.frame = CGRect(x: 0, y: 0, width: estimatedFrame.width + 16 + 8, height: estimatedFrame.height + 20)
} else {
cell.msgTextView.frame = CGRect(x: collectionView.frame.width - estimatedFrame.width - 16 - 8, y: 0, width: estimatedFrame.width + 16, height: estimatedFrame.height + 18)
cell.textBubbleView.frame = CGRect(x: collectionView.frame.width - estimatedFrame.width - 16 - 8 - 8, y: 0, width: estimatedFrame.width + 16 + 8, height: estimatedFrame.height + 20)
}
}
cell.configureCell(msg: message)
return cell
} else {
return MessageCell()
}My problem is when I send a new message, the cells get reload and animated again to rotate 180ºfunc controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
if type == .insert {
blockOperations.append(BlockOperation(block: {
self.msgsCollectionView.insertItems(at: [newIndexPath!])
}))
}
}
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
if self.controller.fetchedObjects!.count > 0 {
self.msgsCollectionView.reloadData()
}
}Please check the output:https://imgur.com/koYLhrMHow do I avoid cell layout effect??
Post not yet marked as solved
I was not able to delete any record type from CloudKit dashboard. I'm deleting from Development Environment. Don't know what problem is there. I always get this error while deleting any record types.
Post not yet marked as solved
Hi,I have Names stored in CloudKit.I want display list of that names as a suggestion (like NSComboBox) in NSTextField.Is there any way to achieve this?
I'm working to get a solution since 15 days. Searched everywhere but didn't get rid of this problem. I have feeds to show in my UITableView. And I'm caching images. I'm loading images from firebase. The single feed contains more than one images. So I'm using Horizontal scrollviewand adding images to it.I'm also using pagination for fetching feeds from firestore. The problem is when I scroll to bottom of tableView, the cell first shows previous feed's images then showing correct images. That's why I'm clearing contents of my cell's ScrollView, but still same problem persists.HomeViewController Codefunc tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let feed = feeds[indexPath.row]
let user = feed.user
if let cell = tableView.dequeueReusableCell(withIdentifier: "FeedCell", for: indexPath) as? FeedCell {
if let images: [UIImage] = HomeViewController.postImagesCache.object(forKey: feed.postID as NSString) as? [UIImage] {
if let profileImage = HomeViewController.profileImageCache.object(forKey: user.profileImageUrl as NSString) {
cell.configCell(feed: feed, images: images, profileImage: profileImage, indexPath: indexPath)
} else {
cell.configCell(feed: feed, images: images, indexPath: indexPath)
}
} else {
tableView.isScrollEnabled = false
if let profileImage = HomeViewController.profileImageCache.object(forKey: user.profileImageUrl as NSString) {
cell.configCell(feed: feed, profileImage: profileImage, indexPath: indexPath)
} else {
cell.configCell(feed: feed, indexPath: indexPath)
}
tableView.isScrollEnabled = true
}
return cell
} else {
return FeedCell()
}
}FeedCell codeoverride func prepareForReuse() {
postMediaView.subviews.forEach{
if $0.restorationIdentifier != "imagesPageControl" {
print("removing subviews")
$0.removeFromSuperview()
}
}
self.profileImageView.image = nil
}
override func awakeFromNib() {
super.awakeFromNib()
profileImageView.layer.cornerRadius = profileImageView.frame.width/2
profileImageView.clipsToBounds = true
}
func configCell(feed: Feed, images: [UIImage]? = nil, profileImage: UIImage? = nil, indexPath: IndexPath) {
self.feed = feed
self.postCaptionLabel.text = feed.item.caption
self.fullnameLabel.text = feed.user.fullname
if images != nil {
self.createImageSlides(images: images!)
} else {
DispatchQueue.global(qos: .userInitiated).async {
var postImages: [UIImage] = []
let urls = feed.item.postImageUrls
let downloadGroup = DispatchGroup()
for i in 0 ..< urls.count {
downloadGroup.enter()
if urls[i] != "" {
let storageRef = Storage.storage().reference(forURL: urls[i])
storageRef.getData(maxSize: 1 * 1024 * 1024, completion: { (data, error) in
if error != nil {
print("Error fetching post images: \(error!)")
downloadGroup.leave()
} else {
if let imgData = data {
if let img = UIImage(data: imgData) {
postImages.append(img)
downloadGroup.leave()
}
}
}
})
}
}
downloadGroup.wait()
DispatchQueue.main.async {
self.createImageSlides(images: postImages)
HomeViewController.postImagesCache.setObject(postImages as AnyObject, forKey: feed.postID as NSString)
}
}
}
if profileImage != nil {
self.profileImageView.image = profileImage
} else {
if feed.user.profileImageUrl != "" {
let storageRef = Storage.storage().reference(forURL: feed.user.profileImageUrl)
storageRef.getData(maxSize: 1 * 200 * 200) { (data, error) in
if error != nil {
print("Error fetching profile image: \(error!)")
} else {
if let imgData = data {
if let img = UIImage(data: imgData) {
self.profileImageView.image = img
self.feed.user.profileImage = img
HomeViewController.profileImageCache.setObject(img as UIImage, forKey: feed.user.profileImageUrl as NSString)
}
} else {
self.profileImageView.image = UIImage(named: "profile_icon")
}
}
}
} else {
self.profileImageView.image = UIImage(named: "profile_icon")
}
}
}
func createImageSlides(images: [UIImage]) {
if images.count < 2 {
let imageView = UIImageView(image: images[0])
imageView.contentMode = .scaleAspectFit
imageView.frame = CGRect(x: 0, y: 0, width: self.postMediaView.frame.width, height: self.postMediaView.frame.height)
imageView.roundCornersForAspectFit(radius: 10)
postMediaView.addSubview(imageView)
pageControl.numberOfPages = 1
} else {
let imageScrollView = UIScrollView()
for i in 0 ..< images.count {
let imageView = UIImageView(image: images[i])
imageView.contentMode = .scaleAspectFit
imageView.frame = CGRect(x: postMediaView.frame.width * CGFloat(i), y: 0, width: postMediaView.frame.width, height: postMediaView.frame.height)
imageView.roundCornersForAspectFit(radius: 10)
imageScrollView.addSubview(imageView)
}
imageScrollView.contentSize = CGSize(width: postMediaView.frame.width * CGFloat(images.count), height: postMediaView.frame.height)
postMediaView.addSubview(imageScrollView)
imageScrollView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
imageScrollView.isPagingEnabled = true
pageControl.numberOfPages = images.count
pageControl.currentPage = 0
postMediaView.bringSubviewToFront(pageControl)
}
}
Hi,I have an label as cutomView toolbarItem. I want to change it's string value from ViewControllers.Any suggestions, how to do it?